Click here to Skip to main content
15,915,319 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
1) Hi, I am Using Asp.net ajax web services using JavaScript.
2) I have a Textbox and a Save Button.
3) On clicking a Save Button, a java script is called which is again calling web service and Returning as '123456' value.
4) Now, in java script, i have PageMethods.<webservicename(parameter,onsuccess());>
5) Now in onsuccess(Response), I am just storing value of Response to Textbox and
alert(<to show="" that="" value="">).
6) But after clicking OK in alert,The value in textbox is Blank.
What to Do.
#Million Thanks in advance;
Posted
Comments
Sergey Alexandrovich Kryukov 10-Aug-15 4:04am    
There is no such thing as "Java script". Java is not a scripting language. ;-)
Yes, you mentioned JavaScript, but did you know that there is also a programming language called "Java", which has nothing to do with JavaScript?
—SA
F-ES Sitecore 10-Aug-15 4:12am    
Post your code, but I suspect the issue is that you're not cancelling the click event of the button so after showing your alert it is maybe then submitting the form. Something like that, without seeing the code it's impossible to say. Your button event should be something like onclick="showAlert(); return false;"
harshil gandhi 10-Aug-15 6:19am    
thanks a alot #F-ES Sitecore.....
It is working now because in my code, i forgot to wrote return false....
Thanks a lot... u r a Saviour...

1 solution

ASP.NET
<asp:updatepanel id="UpdatePanel1" runat="server" xmlns:asp="#unknown">
                        <contenttemplate>
                            <table class="LoginTable">
                                <tr>
                                    <td colspan="2" bgcolor="#74C2FD" class="tdDarkBlue">
                                        <img alt="" class="LoginImage" src="Images/smalllogo.png" />
                                    </td>
                                </tr>
                                <tr>
                                    <td align="right" bgcolor="#A9D5FD" class="tdDarkBlue">
                                        <asp:label id="LblUserid" runat="server" text="User ID:" cssclass="alignLabels"></asp:label>
                                    </td>
                                    <td class="Logintd" bgcolor="#A9D5FD">
                                        <asp:textbox id="TxtUserid" runat="server" onclick="Enterkey();">
                                    CssClass="LoginTextBox"></asp:textbox>
                                    </td>
                                </tr>
                                <tr>
                                    <td align="right" bgcolor="#A9D5FD" class="tdDarkBlue">
                                        <asp:label id="LblPassword" runat="server" text="Password:">
                                    CssClass="alignLabels"></asp:label>
                                    </td>
                                    <td class="Logintd1" bgcolor="#A9D5FD">
                                        <asp:textbox id="TxtPassword" runat="server" cssclass="LoginTextBox"></asp:textbox>
                                    </td>
                                </tr>
                                <tr>
                                    <td bgcolor="#A9D5FD">
                                        <asp:hyperlink id="HyperLink1" runat="server" cssclass="align1">
                                    NavigateUrl="http://google.com">Forgot Password</asp:hyperlink>
                                    </td>
                                    <td bgcolor="#A9D5FD">
                                         
                                        <asp:button id="BtnSave" runat="server" text="Save" cssclass="LoginButton">
                                    onclientclick="return Enterkey1();"/>
                                          
                                        <asp:button id="BtnCancel" runat="server" text="Cancel">
                                    CssClass="LoginButton" />
                                    </asp:button></asp:button></td>
                                </tr>
                            </table>
                        </contenttemplate>
                    </asp:updatepanel>

---------------------------------------------------------------------------------------
My Java Script Code
HTML
script type="text/javascript">

           function Enterkey1() {
               PageMethods.password(document.getElementById("<%=TxtUserid.ClientID%>").value, OnSuccess);
               return false;      //i Forgot to write this here
           }

           function OnSuccess(result) {
               document.getElementById("<%=TxtUserid.ClientID%>").value =                                         result.toString();
               alert(result);
           }

    </script>


---------------------------------------------------------------------------------------
C#
namespace Sample2
{
    public partial class Login : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
          
            //Session[""]
        }

       
        [System.Web.Services.WebMethod]
        public static string password(string name)
        {
            string pass = "123456";
            return pass;
        }

    }
}
 
Share this answer
 
v5

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