ANP*_*ANP 5 c# asp.net user-controls
我正在使用一个用户控件,其中有一个名为"btn_Save"的按钮.我需要在单击用户控件"btn_Save"按钮时触发电子邮件.但是我在页面后面的aspx代码中执行了这个操作.那么,如何使用C#在代码页面后面执行此操作.
我想您正在询问如何从父Web表单(aspx页面)响应用户控件的按钮单击事件,对吧?这可以通过几种方式完成......
最直接的方法是在父Web表单的代码后面注册一个事件处理程序.就像是:
//web form default.aspx or whatever
protected override void OnInit(EventArgs e)
{
//find the button control within the user control
Button button = (Button)ucMyControl.FindControl("Button1");
//wire up event handler
button.Click += new EventHandler(button_Click);
base.OnInit(e);
}
void button_Click(object sender, EventArgs e)
{
//send email here
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
11369 次 |
| 最近记录: |