Hi,
I have going around this error for a while now.Now i realised , there is nothing wrong with my code.can you please help me realise , Why the erros is being thrown?
I'm calling a javascript function ( on textchanged on text box).In that javascript, i have Used Pagemethods to call a server side function(in Code behind) to check ,if the Customer entered is in database or not?
I have used
1) Script manager and enabled page methods
2) I have declared the server side method with
<System.Web.Services.WebMethod()> _
The roor throws up if i enter anything in the textbox: The Server Method"CheckCust" failed. everytime. But few time, it does not. it works correctly. I don't know under what circumstances, the error is throwing up.
I will paste my code below.PLEASE HELP ME in solving this scandulous error.
Thanks.
'''Server Side function:
<System.Web.Services.WebMethod()> _
Public Shared Function CheckCustomerInDatabase(ByVal Custname As String) As String
Dim MyConn As SqlConnection = New SqlConnection(System.Configuration.ConfigurationManager.AppSettings("StrConn"))If Not (Custname Is Nothing OrElse Custname.Length = 0) Then
If MyConn.State = ConnectionState.Closed Then
MyConn.Open()
End If
If MyConn.State = ConnectionState.Open Then
Try
Dim StrCheckCustomer As String
StrCheckCustomer =
String.Format("Select CompanyName From Customers where Companyname='{0}'", Custname)Dim CmdCheckCustomer As SqlCommand = New SqlCommand(StrCheckCustomer, MyConn)Dim CustExist As String = Convert.ToString(CmdCheckCustomer.ExecuteScalar())If CustExist Is String.Empty Then
Return ("This Customer does not exist in database.To add this Customer,Click on the Icon next the textbox and add customer into Database and then choose it :" & Custname)Else
Return Nothing
End If
Catch ex As SqlExceptionReturn "error"
Finally
MyConn.Close()
End Try
End If
End If
End Function
===Javascript
function
{
CheckCustomerTextBox=document.getElementById(id);
CheckCustomer=CheckCustomerTextBox.value;
PageMethods.CheckCustomerInDatabase(CheckCustomer,CallSuccess,CallFailed);
}
{
{
alert(result);
}
}
CheckCustInDB(id)var CheckCustomerTextBox;var CheckCustomer;function CallSuccess(result)if(result!=null)
function
{
alert(error.get_message());
}
CallFailed(error)
}
<
asp:ScriptManager ID="ScriptManager1" runat="server" EnablePageMethods="true">
</
asp:ScriptManager>