使用ASP.NET this.Page作为条件在用户控件中隐藏标签

时间:2019-04-02 04:46:20

标签: c# asp.net asp.net-mvc webforms user-controls

我是使用ASP.NET的新手,我只是想问一下如何从用户控件中获取父页面并将其用作隐藏目录的条件

我尝试过使用

Equatable

但是由于var Pagechk = this.Page; Page page = HttpContext.Current.Handler as Page; if(Pagechk == "ASP.app_car_viewnewcarsdelivered_aspx") { lblCarDeliveryDate.Visible = false; } 似乎永远无法正常工作 还尝试了cannot be applied to operand type of 'Page' and 'string',但是即使添加了Page

的转换也似乎没有用

1 个答案:

答案 0 :(得分:1)

如果要显示和隐藏HTML内容,可以使用CSS样式。 喜欢:

<div id="test"></div>

if(true){
    test.Style.Add("display", "inherit");
}else{
    test.Style.Add("display", "none");
}