c# - 无法从内容页访问母版页的 <input type ="button">

标签 c# html asp.net

我有一个

<input type="button" id="Button1">
在我的 Master1.master主页。 (位于 <div> 中)。

我还有一个内容页Main.aspx . 我想将按钮的可见性设置为 true当我访问内容页面时 Main.aspx ,例如,从另一个页面。 (我有一个 Login.aspx 页面,在我插入 user/psw 并按下一个按钮后,我被重定向到 Main.aspx )。

我添加了指令 <%@ MasterType virtualpath="~/Master1.master" %> 我正在使用以下代码

Button home = new Button();
home = (Button)Master.FindControl("Button1");
home.Visible = false;

但是我得到一个 NullReferenceException当我尝试运行它时。 所以基本上我看不到“Button1”。 我试图将值更改为 headContentHolder1有了这些,它就能完美运行。

谁能帮帮我?

最佳答案

您不能访问不是服务器端控件的输入:

你需要:

<input type="button" id="Button1" runat="server">

关于c# - 无法从内容页访问母版页的 &lt;input type ="button">,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30582829/

相关文章:

jquery - 阻止 UI 无法阻止 div

c# - 停止双重回发

c# - 使类中所有成员的访问修饰符成为一个

html - table/html 中的子选择器规则

php - PHP邮件功能无法完成电子邮件的发送

javascript - 打印全日历时隐藏按钮

c# - FindControl 找不到我动态添加的控件

c# - 为什么 _ret 的计算结果为 true,它不应该计算为 false(位运算符)吗?

javascript - 即使使用 stopPropagation 也会触发父元素

asp.net - 当我有 Membership.GetUser().ProviderUserKey 时,MVC3 从另一个表获取 Id