Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 6 of 6
  1. #1
    New to the CF scene
    Join Date
    Jun 2009
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Postback and ClientClick

    Hej all,

    I have this issue.
    Code:
     <asp:Button PostBackUrl="www.google.com" runat="server" OnClientClick="Validate();" />
    Problem is that i get to the postback page before the validation is finished. In fact my validation is saving something in the database and there is my problem.

    Anyone has any suggestions?

  • #2
    Senior Coder DanInMa's Avatar
    Join Date
    Nov 2010
    Location
    Salem,Ma
    Posts
    1,577
    Thanks
    13
    Thanked 248 Times in 248 Posts
    this is probably a .net issue and not a JavaScript issue.

  • #3
    New to the CF scene
    Join Date
    Jun 2009
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts
    hmm... i will look at the problem from that side also. 10x

    I did. if i run with firebug or debug in VS then it actually saves. So saving in DB is ok every time i am debugging.
    Last edited by alinulms; 12-28-2011 at 12:44 PM.

  • #4
    New to the CF scene
    Join Date
    Jun 2009
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Still cannot fix it. Can anybody suggest anything of any kind? Thank you

  • #5
    Supreme Master coder! Philip M's Avatar
    Join Date
    Jun 2002
    Location
    London, England
    Posts
    18,020
    Thanks
    203
    Thanked 2,538 Times in 2,516 Posts
    Quote Originally Posted by alinulms View Post
    Hej all,

    I have this issue.
    Code:
     <asp:Button PostBackUrl="www.google.com" runat="server" OnClientClick="Validate();" />
    Problem is that i get to the postback page before the validation is finished. In fact my validation is saving something in the database and there is my problem.

    Anyone has any suggestions?
    Code:
    OnClientClick="return Validate()";
    All advice is supplied packaged by intellectual weight, and not by volume. Contents may settle slightly in transit.

    All the code given in this post has been tested and is intended to address the question asked.
    Unless stated otherwise it is not just a demonstration.

  • #6
    Senior Coder alykins's Avatar
    Join Date
    Apr 2011
    Posts
    1,742
    Thanks
    41
    Thanked 191 Times in 190 Posts
    because your button fires a postback and then you have it redirecting- the js probably happens but you never see it bc you are long gone redirected by the time it does anything. why are you using js to validate? you can validate server side if running asp.net and if validation happens then response redirect instead of postback...
    Code:
    <asp:Button runat="server" ID="btn" OnClick="btn_Click" />
    ..............
    btn_Click(object sender, EventArgs e){
    // get all you validation fields 
    // validate them based on parameters you define
    // if (validate){
    //*assuming save something to a DB?
    //Response.Redirect("http://www.google.com");
    //else
    //do whatever it is you want to do if validation fails
    }

    I code C hash-tag .Net
    Reference: W3C W3CWiki .Net Lib
    Validate: html CSS
    Debug: Chrome FireFox IE


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •