Reset checkbox after form submission

J

Joe Bloggs

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;
}

}
 
I

Ignacio Machin \( .NET/ C# MVP \)

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 said:
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;
}

}
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top