views:

311

answers:

1

Just wondering if you know how to accessing controls on a sharepoint master page in code at runtime, I using

System.Web.UI.HtmlControls.HtmlGenericControl logout = (System.Web.UI.HtmlControls.HtmlGenericControl)this.Master.FindControl("logout_switch");

logout.Style["display"] = "block;";

Which seems to find the control but the changes made to that control aren’t reflected on postback eg. the div logout control isn’t visible.

Is this possible in sharepoint master pages ?

A: 

Very well you can access the Controls in the Master Page, accessing the SharePoint Master page is no different from the ASP.NET master page and the code you have written for is right. From your question its clear that logout is not null. which means that it is there and the div has runat="server". If any of these is false then you need to adjust the code accordingly.

Also check where you call the code

logout.Style["display"] = "block";

Another alternate I would suggest is to do this stuff in the Client side if you are able to do. Small java script code to show or hide the control,

function setControl(show){ if (show) login.style.display='block'; else login.style.display='none';}

And call the above code from server side RegersterStartupScript

Else you can try using the LoginStatus Control

}

Kusek
cheers,I was applying the change to the masterpage in one page and then redirecting to another and assuming that the masterpage change would be persistent.