html - OnClick not firing when using both OnClick and OnClientClick -
i've inherited system i'm trying alter adding validation.
i've attempted put validation method on client click, , depending on whether fails or not, change viewstate next page.
however, onclick method not being called when clientclick returns true.
here aspx button;
<asp:button id="btnsavemile" usesubmitbehavior="false" onclick="btnsavemile_onclick" onclientclick="return milestonedatevalidation()" width="149" cssclass="button" runat="server" text="save later" />
how gets rendered chrome;
<input type="button" name="btnsavemile" value="save edit" onclick="return milestonedatevalidation();__dopostback('btnsavemile','')" id="btnsavemile" class="button ui-button ui-widget ui-state-default ui-corner-all" style="width:149px;" role="button" aria-disabled="false">
the validation (simplified) used check dates in chronological order;
function milestonedatevalidation() { var datefields = new array(); var flag = true; var date1; var date2; datefields = $("#completeddatestage1, #completeddatestage2, #completeddatestage3, #completeddatestage4, #completeddatestage5").filter(function() { return this.value.length !== 0; }) var length = datefields.length; if (length > 1) { (var = 1; < length; i++) { date1 = date.parse(datefields[i].value.replace(new regexp("-", "gm"), " ")); date2 = date.parse(datefields[i - 1].value.replace(new regexp("-", "gm"), " ")); if (date1 < date2) { flag = false; break; } } } return flag; }
the button click method;
public void btnsavemile_onclick(object sender, eventargs e) { savemilestones(false); response.redirect("default.aspx?id=" + strcid); }
i'm new web applications, can't spot glaring faults, except btnsavemile_onclick isn't being called on postback.
looking @ other posts, i've noticed button onclick rendered as;
onclick="return milestonedatevalidation();__dopostback('btnsavemile','onclick')"
however mine being rendered as;
onclick="return milestonedatevalidation();__dopostback('btnsavemile','')"
is insignificant, or problem? if so, why blank, or how should correct it?
i've read many articles here on so, , tried many solutions, none have been able solve issue, i'm ready start pulling hair out. have ideas?
as you've seen, when function returns true or false, doesn't post back. modify onclientclick logic follows:
onclientclick="if (!milestonedatevalidation()) {return false;}"
so return false when result of validation false. otherwise, posts back.
Comments
Post a Comment