简体   繁体   中英

Accessing controls on a sharepoint master page

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 ?

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

}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM