访问sharepoint主页面上的控件

时间:2022-02-11 14:50:17

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

只是想知道你是否知道如何在运行时访问代码中的sharepoint主页上的控件,我使用

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

System.Web.UI.HtmlControls.HtmlGenericControl logout =(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母版页中是否可行?

1 个解决方案

#1


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.

很好,您可以访问母版页中的控件,访问SharePoint母版页与ASP.NET母版页没有什么不同,您编写的代码是正确的。从您的问题可以看出,注销不是空的。这意味着它在那里,div有runat =“server”。如果其中任何一个是错误的,那么您需要相应地调整代码。

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控件

}

#1


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.

很好,您可以访问母版页中的控件,访问SharePoint母版页与ASP.NET母版页没有什么不同,您编写的代码是正确的。从您的问题可以看出,注销不是空的。这意味着它在那里,div有runat =“server”。如果其中任何一个是错误的,那么您需要相应地调整代码。

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控件

}