本文介绍了用户控制按钮单击后,关注页面各自的文本框的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好



我在母版页面的webform中有一个3文本框。当第二个或第三个或第一个文本发生更改时,将打开一个包含一个按钮的用户控件。当我单击用户控件中的按钮时,应该聚焦相应的文本更改文本框。我尝试了以下代码



在UserControl中

公共事件EventHandler ButtonClickDemo;

Hi all

I am having a 3 textbox in my webform inside the master page . when text changed of 2nd or 3rd or 1st happens one usercontrol will open which contains one button.When i click the button in user control ,the respective text changed text box should be focused. I tried the following code

In UserControl
public event EventHandler ButtonClickDemo;

protected void imgPopupClose_Click(object sender, EventArgs e)
   {
       ButtonClickDemo(sender, e);
   }



在网页中



在页面

popMsg.ButtonClickDemo + = new EventHandler(Demo1_ButtonClickDemo);

这里 popMsg 是usercontrol



protected void Password_TextChanged(object sender,EventArgs e)

{

Session [s] =Password.ID;

popMsg.Message =请输入有效密码;

popMsg.ShowPopUp();

}


In Web Page

In page
popMsg.ButtonClickDemo += new EventHandler(Demo1_ButtonClickDemo);
here popMsg is usercontrol

protected void Password_TextChanged(object sender, EventArgs e)
{
Session["s"] = "Password.ID;
popMsg.Message = "Please enter valid password";
popMsg.ShowPopUp();
}

protected void Demo1_ButtonClickDemo(object sender, EventArgs e)
    {
        string s = Session["s"].ToString();
        this.FindControl(s).Focus();//here am getting error as object reference not set to instance of the object

    }

推荐答案

this.Page.FindControl("controlName")



从页面中找到控件从主页面你可以使用


And from master page you can find control using

this.Page.Master.FindControl("controlName")



这篇关于用户控制按钮单击后,关注页面各自的文本框的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-23 00:16
查看更多