Wrox Programmer Forums
Go Back   Wrox Programmer Forums > .NET > Other .NET > General .NET
|
General .NET For general discussion of MICROSOFT .NET topics that don't fall within any of the other .NET forum subcategories or .NET language forums.  If your question is specific to a language (C# or Visual Basic) or type of application (Windows Forms or ASP.Net) try an applicable forum category. ** PLEASE BE SPECIFIC WITH YOUR QUESTION ** When posting here, provide details regarding the Microsoft .NET language you are using and/or what type of application (Windows/Web Forms, etc) you are working in, if applicable to the question. This will help others answer the question without having to ask.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the General .NET section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old July 29th, 2004, 08:22 AM
Authorized User
 
Join Date: Jun 2004
Posts: 18
Thanks: 0
Thanked 0 Times in 0 Posts
Default C# reset of checkbox after form submission

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

    }
 
Old July 29th, 2004, 09:06 AM
planoie's Avatar
Friend of Wrox
 
Join Date: Aug 2003
Posts: 5,407
Thanks: 0
Thanked 16 Times in 16 Posts
Default

I think you should try an asp:button instead of the input reset.

<asp:button id="cmdClearCheckBoxes" runat="server" onclick="Reset1_ServerClick" />
 
Old July 29th, 2004, 10:12 AM
Authorized User
 
Join Date: Jun 2004
Posts: 18
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Hey thanks,
I tried adding
<asp:button id="cmdClearCheckBoxes" runat="server" onclick="Reset1_ServerClick" />

but I get a 'WebApplication1.WebForm1.Reset1_ServerClick(objec t, System.EventArgs)' is inaccessible due to its protection level error, any idea what that is?
 
Old July 29th, 2004, 10:25 AM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 1,110
Thanks: 0
Thanked 3 Times in 3 Posts
Default

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

Try changing private to public...

 
Old July 29th, 2004, 10:28 AM
Authorized User
 
Join Date: Jun 2004
Posts: 18
Thanks: 0
Thanked 0 Times in 0 Posts
Default

I tried changing to public (below), still did not work, is it the call in InitializeComponent() that's the problem ?



public void cmdClearCheckBoxes_Click(object sender, System.EventArgs e)
        {

        }

private void InitializeComponent()
        {
            this.GetSelections.Click += new System.EventHandler(this.GetSelections_Click);
            this.DemoGrid.SelectedIndexChanged += new System.EventHandler(this.DemoGrid_SelectedIndexCha nged);
            this.cmdClearCheckBoxes.Click += new System.EventHandler(this.cmdClearCheckBoxes_Click) ;
            this.Load += new System.EventHandler(this.Page_Load);

        }



 
Old July 29th, 2004, 10:30 AM
Authorized User
 
Join Date: Jun 2004
Posts: 18
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Sorry I changed the wrong one -

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

Try changing private to public...

This worked! Thanks again







Similar Threads
Thread Thread Starter Forum Replies Last Post
form submission...help!? mdbrueckner ASP.NET 2.0 Basics 1 September 19th, 2007 06:16 PM
how 2 reset a form kanoorani Javascript How-To 6 October 10th, 2005 05:45 AM
Simple Form Submission Maxood Beginning PHP 3 July 17th, 2004 06:03 AM
conditional form submission moushumi Classic ASP Basics 1 March 30th, 2004 08:12 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.