简体   繁体   English

访问Sharepoint主页上的控件

[英]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"); System.Web.UI.HtmlControls.HtmlGenericControl注销=(System.Web.UI.HtmlControls.HtmlGenericControl)this.Master.FindControl(“ logout_switch”);

logout.Style["display"] = "block;"; 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. div注销控件不可见。

Is this possible in sharepoint master pages ? 在SharePoint母版页中可能吗?

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. 很好,您可以访问母版页中的控件,访问SharePoint母版页与ASP.NET母版页没有什么不同,并且所编写的代码是正确的。 From your question its clear that logout is not null. 从您的问题中可以清楚地看出注销不是null。 which means that it is there and the div has runat="server". 这意味着它在那里并且div具有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, 用于显示或隐藏控件的小型Java脚本代码,

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

And call the above code from server side RegersterStartupScript 并从服务器端RegersterStartupScript调用以上代码

Else you can try using the LoginStatus Control 另外,您可以尝试使用LoginStatus控件

} }

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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