Breaking News

Editors Picks

Thursday, December 23, 2010

Server Error in '/' Application and Invalid postback or callback argument

Problem :
Server Error in '/' 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) +358
   System.Web.UI.Control.ValidateEvent(String uniqueID, String eventArgument) +108
   System.Web.UI.WebControls.TextBox.LoadPostData(String postDataKey, NameValueCollection postCollection) +22
   System.Web.UI.WebControls.TextBox.System.Web.UI.IPostBackDataHandler.LoadPostData(String postDataKey, NameValueCollection postCollection) +11
   System.Web.UI.Page.ProcessPostData(NameValueCollection postData, Boolean fBeforeLoad) +381
   System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +2965


Version Information: Microsoft .NET Framework Version:2.0.50727.42; ASP.NET Version:2.0.50727.42


Answer:  Add EnableEventValidation="false"  on Page directory 
<%@ Page Language="C#" AutoEventWireup="true" EnableEventValidation="false"  Codebehind="SearchResults.aspx.cs"
    Inherits="CartridgeSite.SearchResults" %>
Read more ...

Client side validation using javascript

<script language="javascript" type="text/javascript">
function validate2()
{
     
      if (document.getElementById("<%=txtName.ClientID%>").value=="")
      {
                 alert("Enter First Name");
                 document.getElementById("<%=txtName.ClientID%>").focus();
                 return false;
      }
                 
      if (document.getElementById("<%=txtEmail.ClientID%>").value=="")
      {
                 alert("Enter Email");
                 document.getElementById("<%=txtEmail.ClientID%>").focus();
                 return false;
      }
        var emailPat = /^[^@]+@[^@.]+\.[^@]*\w\w$/  ;   
        var emailid=document.getElementById("<%=txtEmail.ClientID %>").value;
        var matchArray = emailid.match(emailPat);
        if (matchArray == null)
        {               
                   alert("Enter Correct Email");
                   document.getElementById("<%=txtEmail.ClientID %>").focus();
                   return false;
        }
       
        if (document.getElementById("<%=txtSubject.ClientID%>").value=="")
      {
                 alert("Enter Subject");
                 document.getElementById("<%=txtSubject.ClientID%>").focus();
                 return false;
      }
        return true;
}
</script>

<table width="90%" border="0" align="center" cellpadding="2" cellspacing="0">
                                        <tr>
                                            <td width="30%">
                                                <strong>Name :</strong></td>
                                            <td width="70%">
                                                <asp:TextBox ID="txtName" runat="server" CssClass="text_field" Style="width: 250px"></asp:TextBox>
                                            </td>
                                        </tr>
                                        <tr>
                                            <td>
                                                <strong>Email ID :</strong></td>
                                            <td>
                                                <asp:TextBox ID="txtEmail" runat="server" CssClass="text_field" Style="width: 250px"></asp:TextBox>
                                            </td>
                                        </tr>
                                        <tr>
                                            <td>
                                                <strong>Subject :</strong></td>
                                            <td>
                                                <asp:TextBox ID="txtSubject" runat="server" CssClass="text_field" Style="width: 250px"></asp:TextBox>
                                            </td>
                                        </tr>
                                        <tr>
                                            <td>
                                                <strong>Description :</strong></td>
                                            <td>
                                                <asp:TextBox ID="txtDescription" runat="server" TextMode="MultiLine" CssClass="text_field"
                                                    Style="width: 350px"></asp:TextBox>
                                            </td>
                                        </tr>
                                        <tr>
                                            <td>
                                                &nbsp;</td>
                                            <td>
                                                &nbsp;</td>
                                        </tr>
                                        <tr>
                                            <td>
                                                &nbsp;</td>
                                            <td>
                                                <asp:ImageButton ID="imgbtnSend" runat="server" OnClientClick="return validate2()" ImageUrl="images/send.png" Width="46"
                                                    Height="24" border="0" OnClick="imgbtnSend_Click" />
                                                <asp:ImageButton ID="imgbtnReset" runat="server" ImageUrl="images/send.png" Width="46"
                                                    Height="24" border="0" OnClick="imgbtnReset_Click" />
                                            </td>
                                        </tr>
                                        <tr>
                                            <td>
                                                &nbsp;</td>
                                            <td>
                                                &nbsp;</td>
                                        </tr>
                                    </table>
Read more ...

Contact Us

Name

Email *

Message *