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?
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
}
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With