Asp.net 单击用户控件内的按钮后,关注aspx页面内的用户控件
我在aspx页面中有一个用户控件,在加载aspx页面后,当我单击该用户控件中的某个按钮时,我希望在该按钮单击操作完成并且再次加载aspx页面后,焦点回到用户控件 用户控件中需要有一个事件,允许.aspx页面订阅该事件,以便在表单发回后可以将焦点设置到用户控件中的元素,如下所示:Asp.net 单击用户控件内的按钮后,关注aspx页面内的用户控件,asp.net,Asp.net,我在aspx页面中有一个用户控件,在加载aspx页面后,当我单击该用户控件中的某个按钮时,我希望在该按钮单击操作完成并且再次加载aspx页面后,焦点回到用户控件 用户控件中需要有一个事件,允许.aspx页面订阅该事件,以便在表单发回后可以将焦点设置到用户控件中的元素,如下所示: public class UserControlClass { // Define event that will be raised by user control to anyone interested i
public class UserControlClass
{
// Define event that will be raised by user control to anyone interested in handling the event
public event UC_Button1ClickEventHandler UC_Button1Click;
public delegate void UC_Button1ClickEventHandler();
// Mechanism to allow event to be raised by user control
private void Button1_Click(System.Object sender, System.EventArgs e)
{
if (UC_Button1Click != null)
{
UC_Button1Click();
}
}
}
userControl1.UC_Button1Click += Button1_Click;
public void Button1_Click(object sender, EventArgs args)
{
// Set focus here to user control element, text box for example
((TextBox)userControl.FindControl("TextBox1")).Focus();
}
现在,在.aspx页面中,您需要订阅用户控件中的事件,并说明实际处理该事件的方法,如下所示:
public class UserControlClass
{
// Define event that will be raised by user control to anyone interested in handling the event
public event UC_Button1ClickEventHandler UC_Button1Click;
public delegate void UC_Button1ClickEventHandler();
// Mechanism to allow event to be raised by user control
private void Button1_Click(System.Object sender, System.EventArgs e)
{
if (UC_Button1Click != null)
{
UC_Button1Click();
}
}
}
userControl1.UC_Button1Click += Button1_Click;
public void Button1_Click(object sender, EventArgs args)
{
// Set focus here to user control element, text box for example
((TextBox)userControl.FindControl("TextBox1")).Focus();
}
最后,click事件处理程序需要存在,如下所示:
public class UserControlClass
{
// Define event that will be raised by user control to anyone interested in handling the event
public event UC_Button1ClickEventHandler UC_Button1Click;
public delegate void UC_Button1ClickEventHandler();
// Mechanism to allow event to be raised by user control
private void Button1_Click(System.Object sender, System.EventArgs e)
{
if (UC_Button1Click != null)
{
UC_Button1Click();
}
}
}
userControl1.UC_Button1Click += Button1_Click;
public void Button1_Click(object sender, EventArgs args)
{
// Set focus here to user control element, text box for example
((TextBox)userControl.FindControl("TextBox1")).Focus();
}
如何使用javascript集中精力?