ASP.NET中在母版页定义了一个Button,我想用这个button控制另一个页面的Textbox,是否能实现,应该怎么写

来源:百度知道 编辑:UC知道 时间:2024/06/28 11:45:18
ASP.NET中在母版页定义了一个Button,我想用这个button控制另一个页面的Textbox,该Textbox我设置了不可输入文本,我想点击button后使其可以输入文本。
是否能实现,应该怎么写。麻烦各位高手了,我刚学ASP.NET,是个菜鸟,还请包涵

//把下面的代码写在你的页中就行就了,我试了,完全可以的。
protected void Page_Load(object sender, EventArgs e)
{
Button Button1 = (Button)this.Master.FindControl("Button1");//Button1是用母版页上的一个button记住不在母版页上为它写任何的事件代码。
Button1.Click += new EventHandler(Button1_Click);
}

protected void Button1_Click(object sender, EventArgs e)
{
TextBox1.ReadOnly = false;
}

你先把母版页拖到textbox页面
在pageload时间设置button属性
protected void Page_Load(object sender, EventArgs e)
{
this.TextBox1.Enabled = false;
}
protected void Button1_Click(object sender, EventArgs e)
{
this.TextBox1.Enabled = true;
}