10 Replies - 5498 Views - Last Post: 28 October 2009 - 06:41 AM Rate Topic: -----

#1 Angate  Icon User is offline

  • New D.I.C Head

Reputation: 2
  • View blog
  • Posts: 28
  • Joined: 05-March 09

Calling Web Service from Javascript

Posted 23 October 2009 - 11:59 AM

I am trying to create a web service that will be called when a user makes an account on my site to determine if the name they chose is available without a post back.

When the input box loose focus (blur), the IsUserNameTaken() javascript funciton is called. For testing purposes, at this point i make the nameNotAvalableDiv visible to prove the function was called. The call back function makes the nameAvalableDiv visible to prove the call back. This does not happen. I don't know if the service is not being called or if it is not doing the call back or what.

This is what I have in the page:

<asp:ScriptManager ID="masterScriptManager" runat="server" EnablePageMethods="true">
			<Services>
				<asp:ServiceReference path="http://localhost/Magnet Minis/WebService/Service.asmx" />
			</Services>
		</asp:ScriptManager>



<script language="javascript" type="text/javascript">

		function IsUserNameTaken() {
			var proposedName = document.getElementById('UserName');
			var obj = document.getElementById('nameNotAvalableDiv')
			obj.style.visibility = 'visible';
			Service.IsUserNameTaken(proposedName, NameCallback);
		}
		function NameCallback(result) {
			alert('NameResponse');
			var obj = document.getElementById('nameAvalableDiv')
			obj.style.visibility='visible';
		}
	</script>


<td>
	<asp:TextBox ID="UserName" runat="server"></asp:TextBox>
	<asp:RequiredFieldValidator ID="UserNameRequired" runat="server" 
								  ControlToValidate="UserName" ErrorMessage="User Name is required." 
								  ToolTip="User Name is required." ValidationGroup="CreateUserWizard1">*</asp:RequiredFieldValidator>
	 <div id="checkNameDiv">
		<div id="nameAvalableDiv" class="NameAvalable" style="visibility: hidden">
			Name Avalable
		</div>
		<div id="nameNotAvalableDiv" class="NameNotAvalable" style="visibility: hidden">	
			Name Not Avalable
		</div>
	</div>
</td>



Web.Config:

<httpHandlers>
	  <remove verb="*" path="*.asmx" />
	  <add verb="*" path="*.asmx" validate="false" type="System.Web.Script.Services.ScriptHandlerFactory, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />
	  <add verb="*" path="*_AppService.axd" validate="false" type="System.Web.Script.Services.ScriptHandlerFactory, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />
	  <add verb="GET,HEAD" path="ScriptResource.axd" type="System.Web.Handlers.ScriptResourceHandler, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" validate="false" />
	</httpHandlers>
	<httpModules>
	  <add name="ScriptModule" type="System.Web.Handlers.ScriptModule, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />
	</httpModules>



Web service:

Option Explicit On
Option Strict On

Imports System.Xml
Imports System.Web
Imports System.Web.Services
Imports System.Web.Services.Protocols
Imports System.Web.Script.Services


<WebService(Namespace:="http://magnetminis.com/")> _
<WebServiceBinding(ConformsTo:=WsiProfiles.BasicProfile1_1)> _
<Global.Microsoft.VisualBasic.CompilerServices.DesignerGenerated()> _
<scriptService()> _
Public Class Service
	Inherits System.Web.Services.WebService

	<WebMethod()> _
	Public Function HelloWorld() As String
		Return "Hello World"
	End Function

	<WebMethod()> _
	Public Function IsUserNameTaken(ByVal trialName As String) As Boolean

		Dim trialNameString As String = Server.HtmlEncode(trialName)
		Dim allUsers As MembershipUserCollection
		allUsers = Membership.GetAllUsers()
		For Each u As MembershipUser In allUsers
			If u.UserName = trialNameString Then
				Return True
				Exit Function
			End If
		Next
		Return False
	End Function

End Class



The web service is in its own folder within the IIS solution.

Posted Image



Is there anything obviously wrong here? I have looked all over and I don't see the issue.

Is This A Good Question/Topic? 0
  • +

Replies To: Calling Web Service from Javascript

#2 Jayman  Icon User is offline

  • Student of Life
  • member icon

Reputation: 418
  • View blog
  • Posts: 9,532
  • Joined: 26-December 05

Re: Calling Web Service from Javascript

Posted 23 October 2009 - 06:58 PM

If you look at the source of the page when you run your project, you will find that ASP.NET renames the elements on the page to a different ID than what you assigned it.

More than likely the javascript is not finding the element.
Was This Post Helpful? 0
  • +
  • -

#3 Angate  Icon User is offline

  • New D.I.C Head

Reputation: 2
  • View blog
  • Posts: 28
  • Joined: 05-March 09

Re: Calling Web Service from Javascript

Posted 23 October 2009 - 07:16 PM

View PostJayman, on 23 Oct, 2009 - 05:58 PM, said:

If you look at the source of the page when you run your project, you will find that ASP.NET renames the elements on the page to a different ID than what you assigned it.

More than likely the javascript is not finding the element.



What element are you referring to?
Was This Post Helpful? 0
  • +
  • -

#4 Jayman  Icon User is offline

  • Student of Life
  • member icon

Reputation: 418
  • View blog
  • Posts: 9,532
  • Joined: 26-December 05

Re: Calling Web Service from Javascript

Posted 24 October 2009 - 09:54 AM

All of them. Post the source for the page after it has been rendered.
Was This Post Helpful? 0
  • +
  • -

#5 Angate  Icon User is offline

  • New D.I.C Head

Reputation: 2
  • View blog
  • Posts: 28
  • Joined: 05-March 09

Re: Calling Web Service from Javascript

Posted 26 October 2009 - 07:43 AM

View PostJayman, on 24 Oct, 2009 - 08:54 AM, said:

All of them. Post the source for the page after it has been rendered.


I made a few changes for this. I moved the web service into the main solution so that the name to it could be resolvable. I also made the name of the service a bit more descriptive.

Page aspx:


<asp:ScriptManager ID="masterScriptManager" runat="server" EnablePageMethods="true">
			<Services>
				<asp:ServiceReference Path="~/asyncWebService.asmx" />
			</Services>
</asp:ScriptManager>





The VB code here is to test resolution to the method.


<script language="javascript" type="text/javascript">

		function IsUserNameTaken() {
			var proposedName = document.getElementById('UserName');
			var obj = document.getElementById('nameNotAvalableDiv')
			obj.style.visibility = 'visible';
			asyncWebService().IsUserNameTaken(proposedName, NameCallback);
		}
		function NameCallback(result) {
			alert('NameResponse');
			var obj = document.getElementById('nameAvalableDiv')
			obj.style.visibility='visible';
		}
	</script>
	
	<script runat="server">
		'intelisence provided asyncWebService().IsUserNameTaken(name) here.
		<System.Web.Services.WebMethod()> _
		<System.Web.Script.Services.ScriptMethod()> _
		Public Shared Function CheckNameAvalability(ByVal name As String) As Boolean
			Return New asyncWebService().IsUserNameTaken(name)
		End Function
			
	</script>





Web Service:

Option Explicit On
Option Strict On

Imports System.Xml
Imports System.Web
Imports System.Web.Services
Imports System.Web.Services.Protocols
Imports System.Web.Script.Services

' To allow this Web Service to be called from script, using ASP.NET AJAX, uncomment the following line.
<System.Web.Script.Services.ScriptService()> _
<WebService(Namespace:="http://magnetminis.com/")> _
<WebServiceBinding(ConformsTo:=WsiProfiles.BasicProfile1_1)> _
<Global.Microsoft.VisualBasic.CompilerServices.DesignerGenerated()> _
Public Class asyncWebService
	Inherits System.Web.Services.WebService

	<WebMethod()> _
	Public Function HelloWorld() As String
		Return "Hello World"
	End Function

	<WebMethod()> _
	Public Function IsUserNameTaken(ByVal trialName As String) As Boolean

		Dim trialNameString As String = Server.HtmlEncode(trialName)
		Dim allUsers As MembershipUserCollection
		allUsers = Membership.GetAllUsers()
		For Each u As MembershipUser In allUsers
			If u.UserName = trialNameString Then
				Return True
				Exit Function
			End If
		Next
		Return False
	End Function

End Class




And here is the rendered page:


[code]


<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head><title>
Minis (working name)
</title>
<script src="login.js" type="text/javascript"></script>
<link href="App_Themes/Default/StyleSheet.css" type="text/css" rel="stylesheet" /><style type="text/css">
.ctl00_masterMenu_0 { background-color:white;visibility:hidden;display:none;position:absolute;left:0px;top:0px; }
.ctl00_masterMenu_1 { text-decoration:none; }
.ctl00_masterMenu_2 { }

</style></head>
<body>
<noscript>Javascript must be enabled and supported for usage of this site!</noscript>
<form name="aspnetForm" method="post" action="login.aspx" onsubmit="java script:return WebForm_onsubmit();" id="aspnetForm">

<div>
<input type="hidden" name="__EVENTTARGET" id="__EVENTTARGET" value="" />
<input type="hidden" name="__EVENTARGUMENT" id="__EVENTARGUMENT" value="" />
<input type="hidden" name="__VIEWSTATE" id="__VIEWSTATE" value="/wEPDwULLTIxNDIzNjY4NzcPZBYCZg9kFgICA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nEAUEMTk4MwUEMTk4M2cQBQQxOTg0BQQxOTg0ZxAFBDE5ODUFBDE5ODVnEAUEMTk4NgUEMTk4NmcQBQQxOTg3BQQxOTg3ZxAFBDE5ODgFBDE5ODhnEAUEMTk4OQUEMTk4OWcQBQQxOTkwBQQxOTkwZxAFBDE5OTEFBDE5OTFnEAUEMTk5MgUEMTk5MmcQBQQxOTkzBQQxOTkzZxAFBDE5OTQFBDE5OTRnEAUEMTk5NQUEMTk5NWcQBQQxOTk2BQQxOTk2ZxYBZmQCAw8QD2QWAh8CBYMBZGRsSGFuZGxlcignY3RsMDBfQ29udGVudFBsYWNlSG9sZGVyMV9DcmVhdGVVc2VyV2l6YXJkMV95RHJvcERvd25MaXN0JywnY3RsMDBfQ29udGVudFBsYWNlSG9sZGVyMV9DcmVhdGVVc2VyV2l6YXJkMV9tRHJvcERvd25MaXN0JylkFgFmZAICD2QWAgIDDw9kFgIeBm9uYmx1cgURSXNVc2VyTmFtZVRha2VuKClkGAMFHl9fQ29udHJvb script:WebForm_DoPostBackWithOptions(new WebForm_PostBackOptions("ctl00$LoginView1$Login1$LoginButton", "", true, "ctl00$ctl01$Login1", "", false, false))" id="ctl00_LoginView1_Login1_LoginButton" style="font-size:X-Small;" />
</td>
</tr>
<tr>
<td align="center"
style="color:Red;">


</td>
</tr>
</table>
</td>
</tr>
</table>
</td>
</tr>
</table>


</div> <!-- MasterLoginDiv -->
<br />
<a href="#ctl00_masterMenu_SkipLink"><img alt="Skip Navigation Links" src="/Magnet%20Minis/WebResource.axd?d=vAHEcMdlgE3CVuEutu1Zuw2&t=633912225720312500" width="0" height="0" style="border-width:0px;" /></a><table id="ctl00_masterMenu" class="ctl00_masterMenu_2" cellpadding="0" cellspacing="0" border="0">
<tr>
<td onmouseover="Menu_HoverStatic(this)" onmouseout="Menu_Unhover(this)" onkeyup="Menu_Key(event)" id="ctl00_masterMenun0"><table cellpadding="0" cellspacing="0" border="0" width="100%">
<tr>
<td style="white-space:nowrap;"><a class="ctl00_masterMenu_1" href="products.aspx?categoryID=0&forceID=1">Marines</a></td>
</tr>

</table></td><td style="width:3px;"></td><td onmouseover="Menu_HoverStatic(this)" onmouseout="Menu_Unhover(this)" onkeyup="Menu_Key(event)" id="ctl00_masterMenun1"><table cellpadding="0" cellspacing="0" border="0" width="100%">
<tr>
<td style="white-space:nowrap;"><a class="ctl00_masterMenu_1" href="cart.aspx">Chaos</a></td>
</tr>
</table></td><td style="width:3px;"></td><td onmouseover="Menu_HoverStatic(this)" onmouseout="Menu_Unhover(this)" onkeyup="Menu_Key(event)" id="ctl00_masterMenun2"><table cellpadding="0" cellspacing="0" border="0" width="100%">
<tr>
<td style="white-space:nowrap;"><a class="ctl00_masterMenu_1" href="java script:__doPostBack('ctl00$masterMenu','Tau')">Tau</a></td>
</tr>

</table></td>
</tr>
</table><a id="ctl00_masterMenu_SkipLink"></a>





<span id="ctl00_timeLabel">10/26/2009 10:42:29 AM</span>
<div id="ctl00_cartUpdatePanel">

<span id="ctl00_cartLabel">0 items in cart.</span>

</div>





</div> <!-- TopControlsDiv -->


</div> <!-- TopCenterDiv -->

</div> <!-- TopDiv -->
<br />
<br />
<br />
<div id ="ContentDiv" class="Content">


<script language="javascript" type="text/javascript">

function IsUserNameTaken() {
var proposedName = document.getElementById('UserName');
var obj = document.getElementById('nameNotAvalableDiv')
obj.style.visibility = 'visible';
asyncWebService().IsUserNameTaken(proposedName, NameCallback);
}
function NameCallback(result) {
alert('NameResponse');
var obj = document.getElementById('nameAvalableDiv')
obj.style.visibility='visible';
}
</script>




<center>
<br />
<br />
<br />
<table>
<tr>
<td>
<table cellspacing="0" cellpadding="1" border="0" id="ctl00_ContentPlaceHolder1_Login1" style="border-collapse:collapse;">
<tr>

<td><table cellpadding="0" border="0">
<tr>
<td align="center" colspan="2">Log In</td>
</tr><tr>
<td align="right"><label for="ctl00_ContentPlaceHolder1_Login1_UserName">User Name:</label></td><td><input name="ctl00$ContentPlaceHolder1$Login1$UserName" type="text" id="ctl00_ContentPlaceHolder1_Login1_UserName" /><span id="ctl00_ContentPlaceHolder1_Login1_UserNameRequired" title="User Name is required." style="color:Red;visibility:hidden;">*</span></td>
</tr><tr>
<td align="right"><label for="ctl00_ContentPlaceHolder1_Login1_Password">Password:</label></td><td><input name="ctl00$ContentPlaceHolder1$Login1$Password" type="password" id="ctl00_ContentPlaceHolder1_Login1_Password" /><span id="ctl00_ContentPlaceHolder1_Login1_PasswordRequired" title="Password is required." style="color:Red;visibility:hidden;">*</span></td>

</tr><tr>
<td colspan="2"><input id="ctl00_ContentPlaceHolder1_Login1_RememberMe" type="checkbox" name="ctl00$ContentPlaceHolder1$Login1$RememberMe" /><label for="ctl00_ContentPlaceHolder1_Login1_RememberMe">Remember me next time.</label></td>
</tr><tr>
<td align="right" colspan="2"><input type="submit" name="ctl00$ContentPlaceHolder1$Login1$LoginButton" value="Log In" onclick="java script:WebForm_DoPostBackWithOptions(new WebForm_PostBackOptions("ctl00$ContentPlaceHolder1$Login1$LoginButton", "", true, "ctl00$ContentPlaceHolder1$Login1", "", false, false))" id="ctl00_ContentPlaceHolder1_Login1_LoginButton" /></td>
</tr>
</table></td>
</tr>
</table>
</td>

<td>
<table cellspacing="0" cellpadding="0" border="0" id="ctl00_ContentPlaceHolder1_CreateUserWizard1" style="border-collapse:collapse;">
<tr style="height:100%;">
<td>
<table border="0">
<tr>
<td align="center" colspan="2">
Sign Up for Your New Account</td>
</tr>

<tr>
<td align="right">
<label for="ctl00_ContentPlaceHolder1_CreateUserWizard1_UserName" id="ctl00_ContentPlaceHolder1_CreateUserWizard1_UserNameLabel">User Name:</label>
</td>
<td>
<input name="ctl00$ContentPlaceHolder1$CreateUserWizard1$UserName" type="text" id="ctl00_ContentPlaceHolder1_CreateUserWizard1_UserName" onblur="IsUserNameTaken()" />
<span id="ctl00_ContentPlaceHolder1_CreateUserWizard1_UserNameRequired" title="User Name is required." style="color:Red;visibility:hidden;">*</span>
<div id="checkNameDiv">

<div id="nameAvalableDiv" class="NameAvalable" style="visibility: hidden">
Name Avalable
</div>
<div id="nameNotAvalableDiv" class="NameNotAvalable" style="visibility: hidden">
Name Not Avalable
</div>
</div>
</td>
</tr>
<tr>

<td align="right">
<label for="ctl00_ContentPlaceHolder1_CreateUserWizard1_Password" id="ctl00_ContentPlaceHolder1_CreateUserWizard1_PasswordLabel">Password:</label>
</td>
<td>
<input name="ctl00$ContentPlaceHolder1$CreateUserWizard1$Password" type="password" id="ctl00_ContentPlaceHolder1_CreateUserWizard1_Password" />
<span id="ctl00_ContentPlaceHolder1_CreateUserWizard1_PasswordRequired" title="Password is required." style="color:Red;visibility:hidden;">*</span>
</td>
</tr>

<tr>
<td align="right">
<label for="ctl00_ContentPlaceHolder1_CreateUserWizard1_ConfirmPassword" id="ctl00_ContentPlaceHolder1_CreateUserWizard1_ConfirmPasswordLabel">Confirm Password:</label>
</td>
<td>
<input name="ctl00$ContentPlaceHolder1$CreateUserWizard1$ConfirmPassword" type="password" id="ctl00_ContentPlaceHolder1_CreateUserWizard1_ConfirmPassword" />
<span id="ctl00_ContentPlaceHolder1_CreateUserWizard1_ConfirmPasswordRequired" title="Confirm Password is required." style="color:Red;visibility:hidden;">*</span>
</td>

</tr>
<tr>
<td align="right">
<label for="ctl00_ContentPlaceHolder1_CreateUserWizard1_Email" id="ctl00_ContentPlaceHolder1_CreateUserWizard1_EmailLabel">E-mail:</label>
</td>
<td>
<input name="ctl00$ContentPlaceHolder1$CreateUserWizard1$Email" type="text" id="ctl00_ContentPlaceHolder1_CreateUserWizard1_Email" />
<span id="ctl00_ContentPlaceHolder1_CreateUserWizard1_EmailRequired" title="E-mail is required." style="color:Red;visibility:hidden;">*</span>

</td>
</tr>
<tr>
<td align="right">
<label for="ctl00_ContentPlaceHolder1_CreateUserWizard1_Question" id="ctl00_ContentPlaceHolder1_CreateUserWizard1_QuestionLabel">Security Question:</label>
</td>
<td>
<input name="ctl00$ContentPlaceHolder1$CreateUserWizard1$Question" type="text" id="ctl00_ContentPlaceHolder1_CreateUserWizard1_Question" />

<span id="ctl00_ContentPlaceHolder1_CreateUserWizard1_QuestionRequired" title="Security question is required." style="color:Red;visibility:hidden;">*</span>
</td>
</tr>
<tr>
<td align="right">
<label for="ctl00_ContentPlaceHolder1_CreateUserWizard1_Answer" id="ctl00_ContentPlaceHolder1_CreateUserWizard1_AnswerLabel">Security Answer:</label>
</td>
<td>

<input name="ctl00$ContentPlaceHolder1$CreateUserWizard1$Answer" type="text" id="ctl00_ContentPlaceHolder1_CreateUserWizard1_Answer" />
<span id="ctl00_ContentPlaceHolder1_CreateUserWizard1_AnswerRequired" title="Security answer is required." style="color:Red;visibility:hidden;">*</span>
</td>
</tr>
<tr>
<td align="center" colspan="2">
<span id="ctl00_ContentPlaceHolder1_CreateUserWizard1_PasswordCompare" style="color:Red;display:none;">The Password and Confirmation Password must match.</span>
</td>

</tr>
<tr>
<td align="center" colspan="2" style="color:Red;">

</td>
</tr>
</table>
<table border="0" cellspacing="5" style="width:100%;height:100%;">
<tr align="right">
<td align="right" colspan="0">

<input type="submit" name="ctl00$ContentPlaceHolder1$CreateUserWizard1$StepNextButton" value="Create User" onclick="java script:WebForm_DoPostBackWithOptions(new WebForm_PostBackOptions("ctl00$ContentPlaceHolder1$CreateUserWizard1$StepNextButton", "", true, "CreateUserWizard1", "", false, false))" id="ctl00_ContentPlaceHolder1_CreateUserWizard1_StepNextButton" />
</td>
</tr>
</table>
</td>
</tr><tr>
<td align="right"><table cellspacing="5" cellpadding="5" border="0">
<tr>
<td align="right"><input type="submit" name="ctl00$ContentPlaceHolder1$CreateUserWizard1$FinishNavigationTemplateContainerID$FinishPreviousButton" value="Previous" id="ctl00_ContentPlaceHolder1_CreateUserWizard1_FinishNavigationTemplateContainerID_FinishPreviousButton" /></td><td align="right"><input type="submit" name="ctl00$ContentPlaceHolder1$CreateUserWizard1$FinishNavigationTemplateContainerID$FinishButton" value="Finish" id="ctl00_ContentPlaceHolder1_CreateUserWizard1_FinishNavigationTemplateContainerID_FinishButton" /></td>

</tr>
</table></td>
</tr>
</table>

</td>
</tr>

</table>
</center>


</div><!-- ContentDiv -->


<div id="BottomDiv" class="Bottom">

<div id="BottomLeftDiv" class="BottomLeft">
<img src="img/BottomLeft.jpg"
alt="BottomLeft"
id="BottomLeftImage"
width="150"
height="150" />
</div> <!-- BottomLeftDiv -->

<div id="BottomCenterDiv" class="BottomCenter">

<script id="siteSeal"
type="text/javascript"
src="//tracedseals.starfieldtech.com/siteseal/get?scriptId=siteSeal&sealId=e9adbe7ef9c246365f9d46b37bd343fd29ebe3cc53769d74e5d7b239a221e393"></script>

<img src="img/static_ssl_v2_lrg1.png"
alt="SSL"
id="SSLImage"
width="95"
height="145" />

<a href="http://jigsaw.w3.org/css-validator/check/referer">

<img style="border:0;width:88px;height:31px"
src="http://jigsaw.w3.org/css-validator/images/vcss"
alt="Valid CSS!" />
</a>


</div> <!-- BottomCenterDiv -->

<div id="BottomRightDiv" class="BottomRight">
<img src="img/BottomRight.jpg"
alt="BottomRight"
id="BottomRightImage"
width="150"
height="150" />
</div> <!-- BottomRightDiv -->

</div> <!-- BottomDiv -->


</div> <!-- PageDiv -->
</center>

<script type="text/javascript">
//<![CDATA[
var Page_Validators = new Array(document.getElementById("ctl00_LoginView1_Login1_UserNameRequired"), document.getElementById("ctl00_LoginView1_Login1_PasswordRequired"), document.getElementById("ctl00_ContentPlaceHolder1_Login1_UserNameRequired"), document.getElementById("ctl00_ContentPlaceHolder1_Login1_PasswordRequired"), document.getElementById("ctl00_ContentPlaceHolder1_CreateUserWizard1_UserNameRequired"), document.getElementById("ctl00_ContentPlaceHolder1_CreateUserWizard1_PasswordRequired"), document.getElementById("ctl00_ContentPlaceHolder1_CreateUserWizard1_ConfirmPasswordRequired"), document.getElementById("ctl00_ContentPlaceHolder1_CreateUserWizard1_EmailRequired"), document.getElementById("ctl00_ContentPlaceHolder1_CreateUserWizard1_QuestionRequired"), document.getElementById("ctl00_ContentPlaceHolder1_CreateUserWizard1_AnswerRequired"), document.getElementById("ctl00_ContentPlaceHolder1_CreateUserWizard1_PasswordCompare"));
//]]>
</script>

<script type="text/javascript">
//<![CDATA[
var ctl00_LoginView1_Login1_UserNameRequired = document.all ? document.all["ctl00_LoginView1_Login1_UserNameRequired"] : document.getElementById("ctl00_LoginView1_Login1_UserNameRequired");
ctl00_LoginView1_Login1_UserNameRequired.controltovalidate = "ctl00_LoginView1_Login1_UserName";
ctl00_LoginView1_Login1_UserNameRequired.errormessage = "User Name is required.";
ctl00_LoginView1_Login1_UserNameRequired.validationGroup = "ctl00$ctl01$Login1";
ctl00_LoginView1_Login1_UserNameRequired.evaluationfunction = "RequiredFieldValidatorEvaluateIsValid";
ctl00_LoginView1_Login1_UserNameRequired.initialv
Was This Post Helpful? 0
  • +
  • -

#6 PsychoCoder  Icon User is offline

  • Google.Sucks.Init(true);
  • member icon

Reputation: 1641
  • View blog
  • Posts: 19,853
  • Joined: 26-July 07

Re: Calling Web Service from Javascript

Posted 26 October 2009 - 08:04 AM

Here's what Jayman was referring to. In your Javascript you're using document.getElementById('UserName'); but if you look at the rendered page there is no control with that name, it's actual name is ctl00_ContentPlaceHolder1_Login1_UserName.

When ASP.NET renders the ASP.NET server controls it doesn't have the same name as you name it in the markup
Was This Post Helpful? 0
  • +
  • -

#7 Angate  Icon User is offline

  • New D.I.C Head

Reputation: 2
  • View blog
  • Posts: 28
  • Joined: 05-March 09

Re: Calling Web Service from Javascript

Posted 26 October 2009 - 07:03 PM

View PostPsychoCoder, on 26 Oct, 2009 - 07:04 AM, said:

Here's what Jayman was referring to. In your Javascript you're using document.getElementById('UserName'); but if you look at the rendered page there is no control with that name, it's actual name is ctl00_ContentPlaceHolder1_Login1_UserName.

When ASP.NET renders the ASP.NET server controls it doesn't have the same name as you name it in the markup



I changed that ID and put a break point in my web service and I still do not see the call happening...Any Ideas?
Was This Post Helpful? 0
  • +
  • -

#8 Jayman  Icon User is offline

  • Student of Life
  • member icon

Reputation: 418
  • View blog
  • Posts: 9,532
  • Joined: 26-December 05

Re: Calling Web Service from Javascript

Posted 27 October 2009 - 08:08 AM

You have problems with your Javascript.

First off, asyncWebService().IsUserNameTaken(proposedName, NameCallback);, you don't have a IsUserNameTaken function that takes 2 paramenters. It only takes the username and the method is called CheckNameAvalability as defined in your source code.

Second, the IsUserNameTaken function returns a boolean which you aren't doing anything with. How are you supposed to determine if the username is valid, if you don't capture the returned value.

Third, you need to look at the generated HTML to get the correct Id's of the elements. The username input field is called ctl00_ContentPlaceHolder1_CreateUserWizard1_UserName in the generated HTML.

I would suggest using the display attribute to determine when the element is visible/hidden.
<div id="nameAvalableDiv" class="NameAvalable" style="display: none">
	Name Avalable
</div>
<div id="nameNotAvalableDiv" class="NameNotAvalable" style="display: none">
	Name Not Avalable
</div>



		function IsUserNameTaken() {
			var userName = document.getElementById('ctl00_ContentPlaceHolder1_CreateUserWizard1_UserName').value;
			
			var result = asyncWebService().CheckNameAvalability(userName);

			if (result == true){
				var obj = document.getElementById('nameAvalableDiv')
				obj.style.display = '';
			}
			else{
				var obj = document.getElementById('nameNotAvalableDiv')
				obj.style.display = '';
			}
		}


Make the changes mentioned and see if you get the results you are looking for.
Was This Post Helpful? 1
  • +
  • -

#9 Angate  Icon User is offline

  • New D.I.C Head

Reputation: 2
  • View blog
  • Posts: 28
  • Joined: 05-March 09

Re: Calling Web Service from Javascript

Posted 27 October 2009 - 02:29 PM

I made the adjustments you suggested, Jayman, but I still have not seen any results from the service. I know the call from the textbox blur is going to the java script function, but I do not see any result. I fiddled with your function to see what parts of it that i am reaching and this is what i came up with.

	<script language="javascript" type="text/javascript">

		function IsUserNameTaken() {

			var userName = document.getElementById('ctl00_ContentPlaceHolder1_CreateUserWizard1_UserName').value;

			var objdiv = document.getElementById('testDiv');
			objdiv.style.display = '';
			objdiv.innerHTML = userName;

			var result = asyncWebService().CheckNameAvalability(userName);

			objdiv.innerHTML = result;

			if (result == true) {
				var obj = document.getElementById('nameAvalableDiv');
				obj.style.display = '';
			}
			else {
				var obj = document.getElementById('nameNotAvalableDiv');
				obj.style.display = '';
			}
		}
	</script>



I am getting the test div to display showing the function is being called and the userName is being retrieved, but i do not see a result from the web service.
Was This Post Helpful? 0
  • +
  • -

#10 Jayman  Icon User is offline

  • Student of Life
  • member icon

Reputation: 418
  • View blog
  • Posts: 9,532
  • Joined: 26-December 05

Re: Calling Web Service from Javascript

Posted 27 October 2009 - 08:06 PM

Have you debugged the web service inside VS and verified the IsUserNameTaken web method is working correctly?
Was This Post Helpful? 0
  • +
  • -

#11 Angate  Icon User is offline

  • New D.I.C Head

Reputation: 2
  • View blog
  • Posts: 28
  • Joined: 05-March 09

Re: Calling Web Service from Javascript

Posted 28 October 2009 - 06:41 AM

View PostJayman, on 27 Oct, 2009 - 07:06 PM, said:

Have you debugged the web service inside VS and verified the IsUserNameTaken web method is working correctly?


Yes I have. Originally it was a service in a separate solution to test it and it worked just fine. I also put break points in it when i debug the site and they don't get hit.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1