I would like this ASP button control to stop calling its event handler when the JavaScript client method IsCorrectPrice() returns false.
<asp:Button ID="btnsubmit" runat="server"
开发者_开发百科 Text="Submit" OnClientClick="javascript:IsCorrectPrice()"/>
btnsubmit_Click(ByVal sender As Object, ByVal e As System.EventArgs)
Handles btnsubmit.Click
How can this be done?
Change your OnClientClick to be like this:
OnClientClick="return IsCorrectPrice();"
If you have the option to use jQuery, you could use this..
$("#btnsubmit").click(function() {
if (!IsCorrectPrice()) {
e.preventDefault();
}
});
*Note:
Using the OnClientClick right there in the DOM starts to get unmaintainable after the most basic scenarios.
Also, the #btnsubmit may not be the exact id of your button, but that depends on what version of ASP.Net you are using and if you are using 4, what your ClientIdMode is set to.
加载中,请稍侯......
精彩评论