开发者

dynamically change body id in masterpage in asp.net 2.0

Greetings,

I'm pretty new to the asp.net platform, and am having trouble doing the simplest of things.

As my title suggests, I'm wanting to dynamically change the body id on my master page in order to change the background and formatting of the page depending on what section of the website you're on. I have an idea on how to implement it, I'm just not versed enough with C# and asp.net to know how to code it.

I realize that people may say to utilize different methods than changing the body ID tag, but in my case with the liquid design of my website (full screen viewing), changing the body ID dynamically would be the easiest and most modular way for the way I have things laid out.

If anyone could shed some light, it would be much appreciated. As I'm a newbie and am still having trouble cal开发者_开发百科ling classes and passing information between pages, being as specific as possible would be also very much appreciated.

Thanks in advance.


Put an id for the body tag in your master page (I've named it body here)

<body runat="server" id="body">

Set the body id in your MasterPage class > Page_Load event (I added the following bit in Site.master.cs to set the body id to the content page's class name)

public partial class MasterPage : System.Web.UI.MasterPage
{
    protected void Page_Load(object sender, EventArgs e)
    {
        // for page specific styling
        body.ID = ContentPlaceHolder.Page.GetType().BaseType.Name;
    }
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜