我有一个
<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”。
我试图将值更改为 head
或 ContentHolder1
有了这些,它就能完美运行。
谁能帮帮我?
最佳答案
您不能访问不是服务器端控件的输入:
你需要:
<input type="button" id="Button1" runat="server">
关于c# - 无法从内容页访问母版页的 <input type ="button">,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30582829/