locked
problem in access text box value in $.ajax RRS feed

  • Question

  • User-1575600908 posted

    hello,

    i created a plugin for use $.ajax , and work with DB without postback,

    now i created a web form that name is services and pass this in $.ajax in url property

    my ajax code is :

    <script type="text/javascript">
            $(document).ready(function () {
                refreshTime({ terget: $('#submitchangepassword') });
                });
            });
    
     function refreshTime(options) {
                $.ajaxService({
                    url: 'http://localhost:1549/Store/Pages/services.aspx?ServiceName=hello-world',
                    data: { oldpassword: $('#oldpassword').val(), newpassword: $('#newpassword').val() },
                    onStartService: function () { $(options.target).addClass('loading'); },
                    onEndService: function () { $(options.target).removeClass('loading'); },
                    onResponse: function (response) {
                        if (response.result == '1') {
                            $.pushMessage({ message: 'success', messageClass: 'success-message', delay: 3000
                        }
                        else {
                            $.pushMessage({ message: 'some error occured', messageClass: 'success-message', delay: 3000 });
                        }
                    }
                });
            }

    html code :

                <input type="text" id="oldpassword" name="oldpassword" class="txt-changepassword" value="old" />
                <input type="text" id="newpassword" name="newpassword" class="txt-changepassword" value="new" />
               <input type="text" id="confirmpassword" class="txt-changepassword" />
                <input type="button" id="submitchangepassword" onclick="refreshTime({ target: this });" value="change password" class="btn-search" />

    in services.cs i want get querystring & oldpassword & newpassword value,i get querystring value correctly but i get null for oldpassword & newpassword :(

    i take picutre from my error

    http://tinypic.com/view.php?pic=33axt9w&s=5

    http://i42.tinypic.com/1zof7le.png

    my services.cs code:

    protected void Page_Load(object sender, EventArgs e)
            {
                System.Threading.Thread.Sleep(2200);
                string serviceName = this.Request.QueryString["ServiceName"];
                if (!string.IsNullOrEmpty(serviceName))
                {
                    switch (serviceName.ToLower().Trim())
                    {
                        case ("hello-world"):
                            string oldpassword = Request.Form["oldpassword"];
                            string newpassword = Request.Form["newpassword"];
    
                            try
                            {
                                System.Web.Security.MembershipUser usr = System.Web.Security.Membership.GetUser();
                                if (usr.ChangePassword(oldpassword, newpassword))
                                    ResponseResultCollection["result"] = "1";
                                else
                                    ResponseResultCollection["result"] = "0";
                            }
                            catch (Exception ex) { Response.Write("An exception occurred: " + Server.HtmlEncode(ex.Message) + ". Please re-enter your values and try again."); }
                            break;
                    }
                }
                Response.Write(this.GenerateResponseResult());
                Response.End();
            }
    Wednesday, September 11, 2013 2:28 AM

Answers

  • User-933407369 posted

    hi sadeq.hatami ,

    Wrap the TextBox in a nother update panel , and set the updatePanel UpdateMode to "Conditional" ,

     then on partial postback and after you changed the TextBox text , call the Update() method for the UpdatePanel That contains the TextBox .

    refer to:

    http://forums.asp.net/t/1332939.aspx

    i hope it helps you.

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Tuesday, September 17, 2013 9:08 AM

All replies

  • User527778624 posted

    Hi,

    Try writing that JS code before closing the </body> tag. but not in <head> tag.

    Wednesday, September 11, 2013 3:28 AM
  • User-1575600908 posted

    Hi,

    Try writing that JS code before closing the </body> tag. but not in <head> tag.

    i try this but not solved my problem :(

    Wednesday, September 11, 2013 3:34 AM
  • User-933407369 posted

    hi sadeq.hatami ,

    Wrap the TextBox in a nother update panel , and set the updatePanel UpdateMode to "Conditional" ,

     then on partial postback and after you changed the TextBox text , call the Update() method for the UpdatePanel That contains the TextBox .

    refer to:

    http://forums.asp.net/t/1332939.aspx

    i hope it helps you.

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Tuesday, September 17, 2013 9:08 AM