Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

User control click event

Tags:

c#

asp.net

In user control i have a customised button. Iam using this user control on aspx page. when the button in the user control is clicked checkboxes and label in the aspx page should be cleared. Can you please let me know how to accomplish this?

like image 758
xrx215 Avatar asked Feb 28 '23 10:02

xrx215


2 Answers

in your usercontrol you need to create a public eventhandler

public event EventHandler UpdateParentPage;

and in your usercontrol's button clicked event, put

protected void btn_Click(object sender, EventArgs e)
        {
                if (this.UpdateParentPage != null)
                  UpdateParentPage(sender, e);
        }

on your parent page code behind, set the event handler for your usercontrol:

userControl.UpdateParentPage+= new EventHandler(userControl_UpdateParentPage);

then, implement the new event handler on your parent page:

protected void userControl_UpdateViewState(object sender, EventArgs e)
{
        //clear your checkboxes and label here
}
like image 132
madatanic Avatar answered Mar 07 '23 18:03

madatanic


Some time ago I had to do a similar implementation and came up with creating a Reset-Button-Click event handler.

And ended up with having something really simple like this:

protected void ButtonReset_Click(object sender, EventArgs e) {
    if (!TextBox1.Enabled || !ButtonSubmit.Enabled) {
        TextBox1.Enabled = true;
        ButtonSubmit.Enabled = true;
    }
    VieStateData.ResetSession(); // Created a dedicated class to handle the data and session state
    TextBox1.Text = string.Empty;
    TextBox2.Text = string.Empty;

    // More controls to modify

 }

There are, of course, other implementations that allow you to scale / enhance your application in a later matter.

Cheers

like image 30
Faizan S. Avatar answered Mar 07 '23 16:03

Faizan S.