By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,679 Members | 2,469 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,679 IT Pros & Developers. It's quick & easy.

Reset checkbox after form submission

P: n/a
I have a form which includes a checkbox field. I need to add a reset, I
add a HTML reset it works fine before I submit the form but not after. I
know I must add some code to reset the checkbox on the onclick event of
the reset button but I don't know what the code should be. Below is the
HTML for the Data grid that has the check box and the code from the C#
behind code for the reset button. If someone could point me in the right
direction I would be very grateful.

HTML

<form id="Form1" method="post" runat="server">
<asp:datagrid id="DemoGrid" style="Z-INDEX: 104; LEFT: 8px; POSITION:
absolute; TOP: 200px" runat="server" Font-Size="XX-Small"
DataKeyField="customer">
<Columns>
<asp:TemplateColumn HeaderText="Run">
<ItemTemplate>
<asp:CheckBox ID="myCheckbox" Runat="server" />
</ItemTemplate>
</asp:TemplateColumn>

</Columns>
</asp:datagrid>
<input type='reset' value='Reset' style="Z-INDEX: 105; LEFT: 168px;
POSITION: absolute; TOP: 80px" id="Reset1" name="Reset1" runat="server">
</form>

#C Code

private void Reset1_ServerClick(object sender, System.EventArgs e)
{

foreach(DataGridItem DemoGridItem in DemoGrid.Items)
{
CheckBox myCheckbox = (CheckBox)DemoGridItem.Cells[0].Controls[1];
myCheckbox.Checked = false;
}

}
*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Nov 16 '05 #1
Share this Question
Share on Google+
1 Reply


P: n/a
Hi Joe,

The Reset1_ServerClick method should be declared as protected or public, not
private
You also need to change the button declaration, like this:

<asp:Button style="Z-INDEX: 105; LEFT: 168px; POSITION: absolute; TOP:
80px"
ID="Reset1" name="Reset1" runat="server" onClick="Reset1_ServerClick"
</asp:Button>

Cheers,

--
Ignacio Machin,
ignacio.machin AT dot.state.fl.us
Florida Department Of Transportation

"Joe Bloggs" <bo********@netscape.net> wrote in message
news:OJ*************@TK2MSFTNGP11.phx.gbl... I have a form which includes a checkbox field. I need to add a reset, I
add a HTML reset it works fine before I submit the form but not after. I
know I must add some code to reset the checkbox on the onclick event of
the reset button but I don't know what the code should be. Below is the
HTML for the Data grid that has the check box and the code from the C#
behind code for the reset button. If someone could point me in the right
direction I would be very grateful.

HTML

<form id="Form1" method="post" runat="server">
<asp:datagrid id="DemoGrid" style="Z-INDEX: 104; LEFT: 8px; POSITION:
absolute; TOP: 200px" runat="server" Font-Size="XX-Small"
DataKeyField="customer">
<Columns>
<asp:TemplateColumn HeaderText="Run">
<ItemTemplate>
<asp:CheckBox ID="myCheckbox" Runat="server" />
</ItemTemplate>
</asp:TemplateColumn>

</Columns>
</asp:datagrid>
<input type='reset' value='Reset' style="Z-INDEX: 105; LEFT: 168px;
POSITION: absolute; TOP: 80px" id="Reset1" name="Reset1" runat="server">
</form>

#C Code

private void Reset1_ServerClick(object sender, System.EventArgs e)
{

foreach(DataGridItem DemoGridItem in DemoGrid.Items)
{
CheckBox myCheckbox = (CheckBox)DemoGridItem.Cells[0].Controls[1];
myCheckbox.Checked = false;
}

}
*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!

Nov 16 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.