User Click Event

In user control, I have a custom button. Iam using this user control on an aspx page. when a button in a user control is clicked, the checkboxes and label on the aspx page should be cleared. Could you let me know how to do this?

+4
source share
4 answers

in your usercontrol you need to create a public event handler

public event EventHandler UpdateParentPage; 

and in the event with the usercontrol button pressed, set

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

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

 userControl.UpdateParentPage+= new EventHandler(userControl_UpdateParentPage); 

then create a new event handler on the parent page:

 protected void userControl_UpdateViewState(object sender, EventArgs e) { //clear your checkboxes and label here } 
+3
source

Some time ago I had to perform a similar implementation and came up with the creation of a Reset-Button-Click event handler.

And in the end, it turned out something really simple:

 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 / improve your application at a later date.

Greetings

+2
source

If you don't mind doing the postback, the easiest way would be to add an event handler to the OnClick event of the button, and then manually set the IsChecked property for CheckBoxes to false and the Text property of the label to an empty line in the event handler.

+1
source

You will need to create an event in your User Control and get this event when you click a button in a user control. Then, on the ASP.NET page, you must create an event handler for this User Control event, and in this event handler you must clear the CheckBox and Label controls as necessary.

Check out this article: Transferring information between content and main pages , with an emphasis on a section called Transferring information from the main page to its content page . This part of the article shows how to do something on the content page when the user performs an action on the main page (for example, clicking a button). The concept is identical to what you want to do with User Control.

In addition, you may find this tutorial useful: Interacting with a content page from the main page . The two articles mentioned here have sample code in both C # and VB.

+1
source

Source: https://habr.com/ru/post/1303146/


All Articles