本文介绍了如果页面不在pageload方法上回发,则调用Webservice的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
团队,
如果页面不在pageload方法上回发,则如何调用Web服务.我正在调用Web服务以在Ajax dropdownlist上显示值.最初它运行良好,但是当我在buttonclick上添加了inesert storeprocedure时
在提交表单数据之前/之后,我收到用户/无效的回发或回调参数解决方案未处理SQL异常"的信息.
请提出建议.
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.
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");
}
}
}
<%@ 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="
推荐答案
这篇关于如果页面不在pageload方法上回发,则调用Webservice的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!