javascript - Why does my no-submit (HtmlButton) still submit? -
i want dynamically make rows, exist along @ first hidden, visible.
i've tried client-side (jquery) route, have had problems that.
i prefer going down server-side (c#) road, , thought had found way accomplish based on this thread , code:
htmlbutton btnaddfoapalrow = null; . . . btnaddfoapalrow = new htmlbutton(); btnaddfoapalrow.attributes["type"] = "button"; btnaddfoapalrow.innerhtml = "+"; btnaddfoapalrow.id = "btnaddfoapalrow"; btnaddfoapalrow.serverclick += new eventhandler(btnaddfoapalrow_click); this.controls.add(btnaddfoapalrow); private void btnaddfoapalrow_click(object sender, eventargs e) { try { shownextfoapalrow(); } catch (exception ex) { string s = string.format("exception occurred: {0}", ex.message); // todo: log somewhere } } //// works first time, because causes page reloaded, setting foapalrowsshowing 2 private void shownextfoapalrow() { switch (foapalrowsshowing) { case 2: foapalrow3.visible = true; foapalrowsshowing = 3; break; case 3: foapalrow4.visible = true; foapalrowsshowing = 4; btnaddfoapalrow.disabled = true; break; } } foapalrow3 = new htmltablerow(); foapalrow3.id = "foapalrow3"; foapalrow3.visible = false; . . . foapalrow3 = new htmltablerow(); foapalrow3.id = "foapalrow3"; foapalrow3.visible = false;
...but no go - first time second row made visible, subsequent mashing of "+" htmlbutton not make third row visible. , stepping through code, see why: page is being submitted each time mash button, adn initial code runs again, setting number of rows visible two, , making row3 visible (never row4).
this looks after mashing button, no matter how many times mash button (one more row should added, never is):
row 1, btw, column caption row; row 2 single row visible default; row3 , row4 exist, not visible @ first.
try using btnaddfoapalrow.attributes.add("onclick", "return false;");
Comments
Post a Comment