ASP.NET Event for User Control
In aspx page, I am using a user control which contains a button. I need to hide the button(which is in user control) when a checkbox(in aspx) is clikced. I have a postback for checkbox. I want to hide the button when the checkbox is checked. In which event I should do th开发者_如何学Ce hiding and unhiding?
I cannot add extra property in user control. Is it possible to access the button using FindControl and disable it? Which event can be used for it?
Please help
Thanks
Lijo
You would do the hiding in the checkbox clicked event.....
Is your question how to get you aspx page to talk to you ascx?
Expose a public method in your ascx and call it from your aspx onSelectChanged for your Checkbox
protected void myCheckBox_CheckedChanged(object sender, EventArgs e)
{
ucMyControl.ButtonVisible = ((CheckBox)sender).Checked;
}
and in your user control define:
public bool ButtonVisible
{
set { myButton.Visible = value; }
}
Are you allowed to modify the user control at all? The best solution is definitely to expose either a public property or method on the user control, and then have the checkbox click event on the page communicate with the user control through the custom property or method.
FindControl may work, however you are breaking the concept of encapsulation if the page knows the ID of the button that is within the user control and shouldn't do this IMHO...
精彩评论