开发者

Hide / Replace ASP.NET WebForms Controls

I am working on a project that requires that the programmers can add asp:hyperlinks to the pages, but I want to replace those with a custom spun asp:hyperlink which checks before render if the end user has a role or not.

So basically I need a way to tell the a开发者_开发问答sp application that where it renders asp:hyperlink to actually render mycontrols:customhyperlink. Is there a way to make it so that the asp:hyperlink goes to my control library instead of System.Web.UI?


I'm going to assume/suggest that you perform the user-check in the code behind. In that case, you could simply have the two controls right next to each other and only make one visible. For example, in the web-form (aspx):

<asp:Hyperlink ID="Link1" ... />
<asp:CustomHyperlink ID="CustLink1" .../>

Then in the code-behind:

if (user.HasRole) {
  CustLink1.Visible = true;
  Link1.Visible = false;
}
else {
  CustLink1.Visible = false;
  Link1.Visible = true;
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜