Click here to Skip to main content
15,898,222 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
HI all!!

i have a button in the footer template of my gridview. when i checked the textbox inside gridview and clicked the button it shows me error but as soon as i change the button to link button it worked. Can anybody tell me why is that so ??? i googled but not found anything that could explain this.

here is my code that didn't worked

XML
<asp:GridView ID="GridView1" runat="server" BackColor="#CCCCCC"
           BorderColor="#999999" BorderStyle="Solid" BorderWidth="3px" CellPadding="4"
               DataKeyNames="ID" ShowFooter="True" CellSpacing="2" ForeColor="Black"
               onrowcommand="GridView1_RowCommand">
           <RowStyle BackColor="White" />

           <Columns>
               <asp:TemplateField HeaderText="Select">
                   <ItemTemplate>
                       <asp:CheckBox ID="chkbxDelete" runat="server" />
                   </ItemTemplate>
                  <FooterTemplate>
                      <asp:Button runat="server" ID="btnDelete" Text="Delete" CommandName="Del"></asp:Button>
                  </FooterTemplate>
               </asp:TemplateField>

           </Columns>

           <FooterStyle BackColor="#CCCCCC"   HorizontalAlign="Center"/>
           <PagerStyle BackColor="#CCCCCC" ForeColor="Black" HorizontalAlign="Left" />
           <SelectedRowStyle BackColor="#000099" Font-Bold="True" ForeColor="White" />
           <HeaderStyle BackColor="Black" Font-Bold="True" ForeColor="White" />
       </asp:GridView>


but as soon as i changed the type to link button it worked.
Posted
Comments
S.P.Tiwari 2-Dec-11 7:50am    
can you send me page behind code where you got error.(with error)..?
ujjwal uniyal 2-Dec-11 7:56am    
this was the error. When i checked the check-boxes and clicked on the button then this error came. I had used breakpoints on the gridview Row command but it didn't reached there and showed me the error.

Server Error in '/FindingControls' Application.
Invalid postback or callback argument. Event validation is enabled using <pages enableEventValidation="true"/> in configuration or <%@ Page EnableEventValidation="true" %> in a page. For security purposes, this feature verifies that arguments to postback or callback events originate from the server control that originally rendered them. If the data is valid and expected, use the ClientScriptManager.RegisterForEventValidation method in order to register the postback or callback data for validation.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.ArgumentException: Invalid postback or callback argument. Event validation is enabled using <pages enableEventValidation="true"/> in configuration or <%@ Page EnableEventValidation="true" %> in a page. For security purposes, this feature verifies that arguments to postback or callback events originate from the server control that originally rendered them. If the data is valid and expected, use the ClientScriptManager.RegisterForEventValidation method in order to register the postback or callback data for validation.

Source Error:

An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.

Stack Trace:

[ArgumentException: Invalid postback or callback argument. Event validation is enabled using <pages enableEventValidation="true"/> in configuration or <%@ Page EnableEventValidation="true" %> in a page. For security purposes, this feature verifies that arguments to postback or callback events originate from the server control that originally rendered them. If the data is valid and expected, use the ClientScriptManager.RegisterForEventValidation method in order to register the postback or callback data for validation.]
System.Web.UI.ClientScriptManager.ValidateEvent(String uniqueId, String argument) +8627417
System.Web.UI.Control.ValidateEvent(String uniqueID, String eventArgument) +72
System.Web.UI.WebControls.Button.RaisePostBackEvent(String eventArgument) +35
System.Web.UI.WebControls.Button.System.Web.UI.IPostBackEventHandler.RaisePostBackEvent(String eventArgument) +10
System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler sourceControl, String eventArgument) +13
System.Web.UI.Page.RaisePostBackEvent(NameValueCollection postData) +36
System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +1565


Version Information: Microsoft .NET Framework Version:2.0.50727.3623; ASP.NET Version:2.0.50727.3618

1 solution

Add the following on your aspx markup inside your directive. (this will be found on Line1 usually.

XML
EnableEventValidation="false"


Please mark as answer and vote 5 if this solved your problem

Best regards,
Eduard
 
Share this answer
 
v2
Comments
ujjwal uniyal 2-Dec-11 11:28am    
i did it before changing on to link button.. since event validation is set to false there is no event getting fired. the code is worthless if any event associated is not getting fired..

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900