How to create a common event for Multiple Controls
In My application i need to create a table with dynamically creating Rows based on the Content of the row, For Ex:
<asp:Table ID="Table1" runat="server">
<asp:TableHeaderRow>
<asp:TableHeaderCell>Is Max</asp:TableHeaderCell>
<asp:TableHeaderCell>Units</asp:TableHeaderCell>
<asp:TableHeaderCell>Cost</asp:TableHeaderCell>
</asp:TableHeaderRow>
<asp:TableRow>
<asp:TableCell>
<asp:CheckBox ID="CheckBox1" runat="server" OnCheckedChanged="CheckBox1_CheckedChanged" AutoPostBack="True" /></asp:TableCell>
<asp:TableCell>
<asp:Text开发者_JS百科Box ID="TextBox1" runat="server"></asp:TextBox></asp:TableCell>
<asp:TableCell><input type="text" name="sds" /></asp:TableCell>
</asp:TableRow>
</asp:Table>
I am Placing these table control in UpdatePanel. Here i have written a CheckedChanged Event upon which i il create a new row from the codebehind. So the problem is to create a common event which needs to be used by all checkboxes in all rows which are even created dynamically.
Please Suggest if u know any solution. Thanks in advance
You can assign the OnCheckedChanged event in code behind when creating the dynamic controls.
A short sample code, missing everything specific, showing the event subscription:
private void createControl () {
CheckBox dynamicCheckbox = new CheckBox();
/* properties */
dynamicCheckbox.CheckedChanged += new EventHandler( Common_CheckedChanged );
/* add to control tree, etc. */
}
精彩评论