ASP.NET OnClientClick=“return false;” doesn't work

后端 未结 7 1143
鱼传尺愫
鱼传尺愫 2020-12-18 23:55

I just want to add some client side (JQuery Javascript) validation in a web user control. I put an OnClientClick handler and the function gets called. BUT, even if I return

相关标签:
7条回答
  • Try changing it to

    OnClientClick="ValidateMail(); return false;" 
    
    0 讨论(0)
  • 2020-12-19 00:08

    Do you have a click event handler (registered via jquery) which returns true? In that case, the return value of OnClientClick is ignored.

    Have a look at my question (and answer): Why doesn't returning false from OnClientClick cancel the postback

    0 讨论(0)
  • 2020-12-19 00:08

    for some reason, although I didn't have any jquery event handlers attached, it didn't work.

    What actually worked was:

    OnClientClick="if (validate_form() == false) return(false);"
    
    0 讨论(0)
  • 2020-12-19 00:11

    oddly enough this worked for me:

    OnClientClick="javascript:SubmitTableData(); return CanSubmit();"
    

    set the return value submit with the first function call:

    function CanSubmit() {    
        return submit;
    }
    

    Hope this helps someone.

    0 讨论(0)
  • 2020-12-19 00:14

    Just add javascript:

    Example:

    javascript:return ValidateMail();
    
    0 讨论(0)
  • 2020-12-19 00:15

    Great answers. I do it this way. Same result- the OnClick event is not fired off if false is returned from Java function.

    OnClientClick = "if (!ValidateDelete()) return false;"
    OnClick="btnDeleteSupplier_Click"
    
    0 讨论(0)
提交回复
热议问题