Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

User control button click event

I am using an user control which have a button named 'btn_Save'.I need to fire an email on clicking the user control 'btn_Save' button. But I have do this from my aspx code behind page.So, How can I do this in code behind page using C#.

like image 511
ANP Avatar asked Sep 09 '10 08:09

ANP


People also ask

Is button click an event?

The onclick event executes a certain functionality when a button is clicked. This could be when a user submits a form, when you change certain content on the web page, and other things like that. You place the JavaScript function you want to execute inside the opening tag of the button.

What control is used to generate a click event?

jQuery click() Method The click event occurs when an element is clicked. The click() method triggers the click event, or attaches a function to run when a click event occurs.

What is click event in VB NET?

The Click event is raised every time a control is double-clicked. For example, if you have event handlers for the Click and DoubleClick events of a Form, the Click and DoubleClick events are raised when the form is double-clicked and both methods are called.


1 Answers

I think you are asking how to respond to the user control's button click event from the parent web form (aspx page), right? This could be done a few ways...

The most direct way would be to register an event handler on the parent web form's code behind. Something like:

//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
}
like image 138
Kurt Schindler Avatar answered Oct 13 '22 01:10

Kurt Schindler