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):

enter image description here

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

Popular posts from this blog

powershell Start-Process exit code -1073741502 when used with Credential from a windows service environment -

twig - Using Twigbridge in a Laravel 5.1 Package -

c# - LINQ join Entities from HashSet's, Join vs Dictionary vs HashSet performance -