Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: ASP.NETJavascript
Hi,
 
I have 2 textboxes ,one label control and one button on aspx page. I want to display result of two textboxes on the label control on buttons onclientclick event.
 
I have one web method and I am calling this method from javascript function.
 
Problem is that when I assign result(ie sum) in the label control then it visible only for 1 second even less than that and disappears. Even no server event is being fired after that.
can you please help.
My code is given below:
  <script type="text/javascript">
        function CallSum() {
            var Num1 = $get('TextBox1');
            var Num2 = $get('TextBox2');
            var lblControl = $get('lblResult');
 
            //call server side function
            PageMethods.Sum(Num1.value, Num2.value, CallSuccess, CallFailed, lblControl);
        }
          function CallSuccess(result, lblControl) {
            //Show the result in lblresult
                lblControl.innerHTML = result;
           }
 
        function CallFailed(result, lblControl) {
            if (result !== null) {
                alert(result.get_message());
            }
        }
    </script>
First Number<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox><br />
   Second Number<asp:TextBox ID="TextBox2" runat="server"></asp:TextBox><br />
 
   Result = <asp:Label ID="lblResult" ClientIDMode="Static" runat="server"></asp:Label><br />
   <asp:Button ID="button1" runat="server" Text="Get SUM" OnClientClick="return CallSum();" />
and server method is:
[System.Web.Services.WebMethod]
        public static int Sum(int n1, int n2)
        {
            try { return n1 + n2; }
 
            catch (Exception ex) { throw ex; }
        }
Thanks in advance.
Vivek.
Posted 24-Jan-13 0:07am
Edited 24-Jan-13 3:23am
v4
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 2

Try:
<asp:Button ID="button1" runat="server" Text="Get SUM" OnClientClick="CallSum(); return false;" />
This should just execute the client side code and stop the execution.
  Permalink  
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

you must return false in the callsum function.
  Permalink  

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

  Print Answers RSS
Your Filters
Interested
Ignored
     
0 Sergey Alexandrovich Kryukov 800
1 OriginalGriff 503
2 Abhinav S 253
3 thatraja 245
4 Emre Ataseven 200
0 Sergey Alexandrovich Kryukov 8,282
1 OriginalGriff 4,750
2 Peter Leow 3,784
3 Maciej Los 3,515
4 Er. Puneet Goel 3,107


Advertise | Privacy | Mobile
Web03 | 2.8.140415.2 | Last Updated 24 Jan 2013
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Use
Layout: fixed | fluid