Reputation: 135
I am trying to change the css class attribute that has been present on the site.master page at run time and I cant really get any head way I have so far tired
mainContainer.Attributes.Add("style", "background-image('myImage.png')");
AND
mainContainer.Attributes.Add("class", "className");
BUT non of these let me change the css of the master file at run time. i am using asp.net using c#
this is the code on the master page
<div class="main">
<asp:ContentPlaceHolder ID="MainContent" runat="server"/>
</div>
Upvotes: 2
Views: 2168
Reputation: 1100
You first need find the control on the master page
Image img = Page.Master.FindControl( "layoutStyleSheet" ) as Image;
then add style to it
img.Attributes.Add("class", "className");
Upvotes: 0
Reputation: 36
ContentPlaceHolder is element wich won't be existed in output html code. It only defines a region. You can try to change div with class "main". Just add runat="server" and id attributes and access from the code.
<div id="MainDiv" class="main" runat="server">
and then
MainDiv.Attributes.Add...
Upvotes: 1
Reputation: 354
You need to partially load the master page in the other child pages like below...
<%@ MasterType VirtualPath="~/Site1.Master" %>
Then in the page load of the child page..put
protected void Page_Load(object sender, EventArgs e)
{
HyperLink contact_menu = (HyperLink)Master.FindControl("contactmenu");
contact_menu.CssClass = "current";
}
Change as per your need.. Enjoy..
Upvotes: 1