简体   繁体   English

隐藏/替换ASP.NET WebForms控件

[英]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. 我正在一个需要程序员可以在页面上添加asp:hyperlinks的项目,但是我想用自定义的spn asp:hyperlink替换那些页面,后者会在渲染之前检查最终用户是否有角色。

So basically I need a way to tell the asp application that where it renders asp:hyperlink to actually render mycontrols:customhyperlink. 因此,基本上,我需要一种方法来告诉ASP应用程序它在何处呈现asp:hyperlink来实际呈现mycontrols:customhyperlink。 Is there a way to make it so that the asp:hyperlink goes to my control library instead of System.Web.UI? 有没有一种方法可以使asp:hyperlink转到我的控件库而不是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): 例如,在网络表单(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;
}

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

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