访问共享点母版页上的控件
只是想知道您是否知道如何在运行时在代码中访问共享点母版页上的控件,我使用
System.Web.UI.HtmlControls.HtmlGenericControl logout = (System.Web.UI.HtmlControls.HtmlGenericControl)this.Master.FindControl("注销_开关”);
logout.Style["显示"] = "块;";
这似乎找到了控件,但对该控件所做的更改并未反映在回发中,例如。 div 注销控件不可见。
这在共享点母版页中可能吗?
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 ?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以很好地访问母版页中的控件,访问 SharePoint 母版页与 ASP.NET 母版页没有什么不同,并且您编写的代码是正确的。
从您的问题可以清楚地看出注销不为空。 这意味着它在那里并且 div 已 runat="server"。 如果其中任何一个是错误的,那么您需要相应地调整代码。
还要检查您调用代码的位置。
我建议的另一个替代方法是在客户端执行此操作(如果您是)
能够做到。 用于显示或隐藏控件的小型 java 脚本代码,
并从服务器端调用上述代码 RegersterStartupScript
否则,您可以尝试使用 登录状态 控制
}
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
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,
And call the above code from server side RegersterStartupScript
Else you can try using the LoginStatus Control
}