Click here to Skip to main content
15,900,511 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi all,

I am having issues with ajax postback. It worked fine in 4 but not on 2.0.
This is my code:

$("#<%=registrationNumberTextBox.ClientID%>").blur(function() {
    if ($(this).val().length > 0) {
            type: "POST",
            url: "registration.aspx/GetAmountDue",
            data: "{'registrationNumber': '" + $(this).val() + "'}",
            contentType: "application/json; charset=utf-8",
            dataType: "json",
            async: true,
            cache: false,
            success: function(msg) {
            error: function(x, e) {
                alert("The call to the server side failed. " + x.responseText);
    } else { $("#<%=amountDueLiteral.ClientID%>").html('0.00'); }

<webmethod()>; _
Public Shared Function GetAmountDue(ByVal registrationNumber As String) As String
    If registrationNumber.Trim.Length > 0 Then
        If Student.IsValidRegistration(registrationNumber) Then
            Dim bi As Student.BasicInformation = Student.GetStudentByRegistrationNumber(registrationNumber)
            If bi.StudentId <> Nothing Then
                Dim result As String = String.Format("{0:n2}", bi.StudentAccount.Debit)
                Return result
            End If
        End If
    End If
    Return "0.00"
End Function

The problem is that, the something returned a result but not displayed on the amountDueLiteral. What do I do?
Updated 25-Nov-11 3:36am
Timberbird 25-Nov-11 9:43am    
Try alerting returned value - what does it show?
[no name] 25-Nov-11 11:06am    
Real developers learn to use a debugger rather than print statements
Timberbird 25-Nov-11 11:29am    
That's how you can tell a real developer - he uses submarine for diving? :) Debugging provides much more information than text output, but do you need it simply to tell whether it's client or server script error? If server returns correct result and everything indeed worked fine before, time to view page source, check jQuery version, read info on val() method, and, if needed, enable client script debugging. Otherwise - obviously debug server code and leave client be
Dylan Morley 25-Nov-11 12:09pm    
Or just use Firebug and put a breakpoint on the callback? :)
awedaonline 25-Nov-11 22:26pm    
Thanks Timberbird,

When I alrted it, I got undefined message.

What should I do?

1 solution

There is no difference with this between 2.0 and 4.0. Have you debugged to ensure that everything is working correctly and it is finding the literal element correctly?
Share this answer
awedaonline 25-Nov-11 22:39pm    
Thanks all,

I tried using alert(msg); and $("#m").html(msg); and it worked.
Note: m is a div not control. It did not work with controls.

But I am supprised why it didnot worked with controls.
[no name] 25-Nov-11 23:04pm    
There is no reason it should not work with an control since it renders HTML elements. If you had debugged you could have inspected the elements and ids to make sure you were getting the expected results. Using alerts and print messages in not how real developers solve problems
awedaonline 27-Nov-11 2:30am    
But I do not know how to use FireBug to debug. Please tell me how?
[no name] 27-Nov-11 3:58am    
Sorry, there isn't enough space here to teach you how to be a developer. Learning where and how to research is a big part of it though. Take the first step.
awedaonline 27-Nov-11 4:10am    
Alright. I just got some tips on how to use firebug through google search.


This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900