Click here to Skip to main content
15,867,568 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Hi Team,
How to call Webservice if page is not postback on pageload method. I am calling a webservice to display values on ajax dropdownlist.Initially it was running fine but when I added inesert storeprocedure on buttonclick

I am getting 'SQL Exception was unhandled by user/Invalid postback or callback argument solution' before /after submit form data.

Please advise.
C#
public partial class Help8 : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        
        if (!Page.IsPostBack)
        {
           
        }
    }
  protected void SubmitButton_Click (object sender, EventArgs e)
  {
      if (Page.IsValid)
      {
          String strConnString = System.Configuration.ConfigurationManager.ConnectionStrings["DatabaseConnectionString"].ConnectionString;
          SqlConnection con = new SqlConnection(strConnString);
          SqlCommand cmd = new SqlCommand();
          cmd.CommandType = CommandType.StoredProcedure;
          cmd.CommandText = "InsertDonationForm";
          cmd.Parameters.Add("@fName", SqlDbType.Int).Value = TxtName.Text.Trim();
          cmd.Parameters.Add("@lName", SqlDbType.Int).Value = TxtLastName.Text.Trim();
          cmd.Parameters.Add("@dob", SqlDbType.Int).Value = Convert.ToDateTime(TxtDateofBirth.Text);
          cmd.Parameters.Add("@@email", SqlDbType.Int).Value = TxtEmail.Text.Trim();
          cmd.Parameters.Add("@gender", SqlDbType.Int).Value = RbtGender.SelectedValue.Trim();
          cmd.Parameters.Add("@continent", SqlDbType.Int).Value = ddlContinent.SelectedItem.Text;
          cmd.Parameters.Add("@country", SqlDbType.Int).Value = ddlCountry.SelectedItem.Text;
          cmd.Parameters.Add("@mNumber", SqlDbType.Int).Value = TxtMobile.Text.Trim();
          cmd.Parameters.Add("@pNumber", SqlDbType.Int).Value = TxtPhone.Text.Trim();
          cmd.Parameters.Add("@iDProof", SqlDbType.Int).Value = TxtIDProof.Text.Trim();
          cmd.Parameters.Add("@document", SqlDbType.Int).Value = TxtEmail.Text.Trim();
          cmd.Parameters.Add("@address ", SqlDbType.Int).Value = TxtAddress.Text.Trim();   
          cmd.Connection = con;
          try
          {
              con.Open();
              cmd.ExecuteNonQuery();
              insertReportLabel.Text = "Donation Form Record inserted sucessfully";
          }
          catch
          {
              insertReportLabel.Text = "Donation Form Record NOT inserted";
          }
          finally
          {
              con.Close();
              con.Dispose();
          }
      }
      else
      {
          Response.Write("hello");
      }
   }
  }

ASP.NET
<%@ Page Title="" Language="C#" MasterPageFile="~/MasterPage.master" AutoEventWireup="true" CodeFile="Help8.aspx.cs" Inherits="Help8" EnableEventValidation="false" Debug="true" %>
<%@ Register TagPrefix="asp" Namespace="AjaxControlToolkit" Assembly="AjaxControlToolkit"%>
<asp:Content ID="Content1" ContentPlaceHolderID="head" Runat="Server">
<asp:Panel ID="Panel2" runat="server" ScrollBars="None" Width="100%" Height="2%" Wrap="true" Direction="LeftToRight" BackColor="Black">
<p style="font-weight: bold; font-style: italic; color:white;font-size:initial"><img src="Image/animated image home.gif" width="60" height="40"/>Donate Your Clothes for Noble Cause:Initiative taken by "Dolly Foundation":Ghana...<img src="Image/animated image home1.gif" width="150" height="40"/></p><br />
Please Find Online Donation below:-
<asp:Content ID="Content2" ContentPlaceHolderID="MainContent" Runat="Server">
<asp:Panel ID="Panel1" runat="server" ScrollBars="Auto" Width="100%" Height="70%" Wrap="true" Direction="LeftToRight" BorderStyle="Groove" ForeColor="White" Font-Bold="true">
<div style="width:49%;height:146px; removed:relative;float:left; removed 0px; removed 0px;">
<div>
        Please fill the Online Donation Form as below:-<br /><br />
<table class="style1">
<tr>
<td style="height: 22px; width: 194px">         First Name:</td>
<td style="height: 22px">
<asp:TextBox ID="TxtName" runat="server" Width="142" style="margin-left: 1px">
<br />
<br />
</td>
<td>
<asp:RequiredFieldValidator
ID="RequiredFieldValidator1"
Display="Dynamic"
runat="server" ErrorMessage="Name is required"
ControlToValidate="TxtName"
ForeColor="Red"
Text="*">

<asp:RegularExpressionValidator
Display="Dynamic"
ForeColor="Red"
ID="RegularExpressionValidator1"
runat="server"
ErrorMessage="Please enter a valid Name "
ValidationExpression="^[a-zA-Z''-'\s]{1,40}$"
ControlToValidate="TxtName"
Text="*">

</td>
</tr>
<tr>
<td style="width: 194px">         Last Name:</td>
<td>
<asp:TextBox ID="TxtLastName" Width="142" runat="server" style="margin-left: 0px">
<br />
<br />
</td>
<td>
<asp:RequiredFieldValidator
ID="RequiredFieldValidator2"
Display="Dynamic"
runat="server" ErrorMessage="LastName is required"
ControlToValidate="TxtLastName"
ForeColor="Red"
Text="*">
<asp:RegularExpressionValidator
Display="Dynamic"
ForeColor="Red"
ID="RegularExpressionValidator2"
runat="
Posted
Updated 29-May-14 17:21pm
v3
Comments
Sunasara Imdadhusen 27-May-14 7:16am    
can you please share .aspx code as well
Member 10778647 29-May-14 11:53am    
Please find updated code with new problem :-
http://forums.asp.net/p/1989586/5707060.aspx?p=True&t=635369605658220094&pagenum=1
Sunasara Imdadhusen 29-May-14 23:21pm    
Please do not post code inside comment box use Improve Question link instead.
Why EnableEventValidation="false" In your code?

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

  Print Answers RSS
Top Experts
Last 24hrsThis month


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