I’m developing a web application using .net/c#/jQuery.
I want to develop an AJAX function in a user register page to detect if the user name has been chosen by others already.
Since the register form is in a user control, and a scriptmanager control is in the master page, I added a ScriptManagerProxy control in that user control. The js function was wrapped into a file called a.js.
The webservice is called Vet.asmx. When called it always reports that “Vet” is undefined, but I don’t know why. The code of ScriptManagerProxy is:
<asp:ScriptManagerProxy ID="ScriptManagerProxy1" runat="server">
<Scripts>
<asp:ScriptReference Path="~/Menu/a.js" />
</Scripts>
<Services>
<asp:ServiceReference Path="~/WebService/Vet.asmx" />
</Services>
</asp:ScriptManagerProxy>
The Vet.cs is
public Vet()
{
//Uncomment the following line if using designed components
//InitializeComponent();
}
[WebMethod]
public string SearchUserName(string name)
{
...
}
My a.js code
jQuery("[id$='tb_UserName']").blur(function() {
var login = jQuery("[id$='tb_UserName']").val();
Vet.SearchUserName(login, SearchUserNameCallback);
});
function SearchUserNameCallback(result) {
if (result == "Y") {
jQuery('#userInfo').html("This user name has already been taken");
} else {
jQuery('#userInfo').html("Congratulations!You have a new user name.");
}
}
I’m sure the web method and the js function have no issues other than it cannot find the “Vet” web service. Any idea?
Is your
Vetclass decorated with the [System.Web.Script.Services.ScriptService] attribute?