ASP.Net LinkButton Prevent Postback Not Working - JavaScript -
i know how prevent javscript within href attribute firing evident in jsfiddle (http://jsfiddle.net/mkarr/knefk/)
however, when logic applied asp.net linkbutton such:
<asp:linkbutton id="btnsubmit" runat="server" text="submit" onclientclick="return formtest.validate(event);" onclick="btnsubmit_click"></asp:linkbutton>
which translates to:
<a onclick="return formtest.validate(event);" id="ctl00_m_g_87932399_e546_4e12_8297_982b811d8cea_ctl00_btnsubmit" href="javascript:webform_dopostbackwithoptions('blah blah blah')">submit</a>
the formtest.validate() method execute correctly , returns false, webform_dopostbackwithoptions
fired after!
can see flaws in logic cannot??
edit:
also, several stack overflow solutions have been accepted issue of them doing virtually have done leading me believe i'm missing simple!
answer:
since cannot answer own question because i'm not reputable yet (lol), here's edit answer:
going off @qbm5's original tip of not using asp.net controls, solve problem, although still not know why initial problem occurred in first place (does when comes asp.net? turn off, on comes mind here) :o)
i replaced linkbutton
asp.net control following:
<input type="submit" value="submit" id="btnsubmitbutton" runat="server" onserverclick="btnsubmitbutton_click" class="submitbtn" />
i bound .submitbtn
's click event via jquery:
$('.submitbtn').on('click', function (e) { if (!instance.validate()) { e.preventdefault(); } });
the trick use onserverclick
, runat="server"
on control getting away linkbutton
goal , postback behavior different.
which translates this:
<input onclick="if (typeof(page_clientvalidate) == 'function') page_clientvalidate(''); " type="submit" id="ctl00_m_g_87932399_e546_4e12_8297_982b811d8cea_ctl00_btnsubmitbutton" value="submit" class="submitbtn">
anyone want take stab @ root cause? need move foward don't have time. :o)
Comments
Post a Comment