Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Ajax help

Status
Not open for further replies.

clanm

Programmer
Joined
Dec 26, 2005
Messages
237
Location
US
I'm using this page as another step towards my goal of seeing if a
number already exists in a database, so I do a SQL count. The tutorial,
, where you type in
the state inital and onblur(), then second box fills with the full
name. This tutorial works, but I'm trying to do a SQL count on the text entered, then notifiy the
user if that number exists or not in a db table. Whatever I type in, the div tag says 'null'.

I can get to where I successfully show the parameter passed to the Ajax Method, stateInitial, and the SQL string via the Return value for the div tag, but that's it. All else gives null.

I have the following code behind for my WebForm1.aspx v1.1 page:


Start code behind:
*****
*****


Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
'Put user code to initialize the page here
AjaxPro.Utility.RegisterTypeForAjax(GetType(WebForm1))
End Sub

<AjaxPro.AjaxMethod()> Public Function GetStateName(ByVal stateInitial As String) As String
'Return stateInitial
Dim strSQL As String = "Select count(*) from WBS_Table where [WBS Number] = '" & stateInitial & "'"
Dim cmd As New OleDbCommand(strSQL, sCon1)
Try
sCon1.Open()
Dim intCnt As Integer = cmd.ExecuteScalar()
sCon1.Close()

If intCnt = 0 Then
Return "This is unique"
Else
Return "Please enter another Number!"
End If
Catch ex As Exception
Return ex.ToString()
Finally
sCon1.Close()
End Try
'Select Case stateInitial.ToUpper()
' Case "CA"
' Return "California"
' Case "NY"
' Return "New York"
' Case "IL"
' Return "Illinois"
' Case Else
' Return "What tha'!"
'End Select
End Function


Here's the html:
*****
*****

<HEAD>
<title>WebForm1</title>
<meta content="Microsoft Visual Studio .NET 7.1" name="GENERATOR">
<meta content="Visual Basic .NET 7.1" name="CODE_LANGUAGE">
<meta content="JavaScript" name="vs_defaultClientScript">
<meta content=" name="vs_targetSchema">
<script language="javascript">
function getStateName(obj)
{
Ajax.WebForm1.GetStateName(obj.value,CallbackFunc);
}
//function CallbackFunc(res)
//{
//document.getElementById('txtStateName').value = res.value;
//}
function CallbackFunc(res){
if (res.error != null)
{
alert(res.error.Message);
}
// else
//{
// alert(res.value);
//}
//document.getElementById('txtStateName').value = res
txtStateName.innerHTML = res.value;
}


</script>
</HEAD>
<body MS_POSITIONING="GridLayout">
<form id="Form1" method="post" runat="server">
<div>State Initial:</div>
<asp:textbox id="txtStateInitial" onblur="getStateName(this);" runat="server"></asp:textbox>
<div id="txtStateName"></div>
</form>
</body>
</HTML>
 
If I insert a breakpoint @ the Ajax methond in the code behind, I can see the correct value for the parameter, and for the SQL string. Those I can write out to a div tag and see they're correct.

It's when I try to use the SQL Command and the rest of the code when I get 'null'
 
Dan,

Thanks for the tip. I just tried the SQL with a button click event to cause a post-back, and it does work correctly.

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top