jquery - ASP.NET - Don't want page to refresh -


I have this function, and I do not want to refresh the page when I click on Add Button. Can you help me

  & lt; Div class = "form-group" & gt; & Lt; For label = "autores" & gt; Autors & lt; / Label & gt; & Lt; Textarea runat = "server" class = "form-control" rows = "1" id = "autores" & gt; & Lt; / Textarea & gt; & Lt; Asp: button runat = "server" OnClientClick = "addAutor ();" Text = "add" cssClass = "btn btn-default" autopostback = false / & gt; & Lt; / Div & gt; & Lt; / Div & gt; & Lt; Div class = "col-md-4" & gt; & Lt; Table id = "list" content & gt; & Lt; TR & gt; & Lt; TD & gt; & Lt; Strong> Autores & lt; / Strong> & Lt; / TD & gt; & Lt; / TR & gt; & Lt; / Table & gt; & Lt; Script & gt; Function addAutor () {var table = document.getElementById ("list"); Var line = table.insertRow (1); Var cell1 = row.insertCell (0); Var cell 2 = Row.Intel (1); Cell1.innerHTML = "new cell 1"; Cell2.innerHTML = "new cell 2"; return false; } & Lt; / Script & gt; & Lt; / Div & gt;  

OK! So ... I also try to do this:

  & lt; Table id = "myTable" & gt; & Lt; TR & gt; & Lt; Td> Row 1 cell1 & lt; / Td> & Lt; Td> Row1 cell2 & lt; / Td> & Lt; / TR & gt; & Lt; TR & gt; & Lt; Td> Row 2 cell 1 & lt; / Td> & Lt; Td> Row 2 cell 2 & lt; / Td> & Lt; / TR & gt; & Lt; TR & gt; & Lt; Td> Row 3 cell 1 & lt; / Td> & Lt; Td> Cry 3 cell 2 & lt; / Td> & Lt; / TR & gt; & Lt; / Table & gt; & Lt; Br> & Lt; Button onclick = "myfunction ()" & gt; Try it & lt; / Button & gt; & Lt; Script & gt; Function myFunction () {var table = document.getElementById ("myTable"); Var line = table.insertRow (0); Var cell1 = row.insertCell (0); Var cell 2 = Row.Intel (1); Cell1.innerHTML = "new cell 1"; Cell2.innerHTML = "new cell 2"; } & Lt; / Script & gt;  

with an HTML button ... but it still does not work because it adds content to the table, but reloads the page, and disapears new content.

  & lt; Esp: Button ID = "Button 1" text = "submit" onclick = "addAutor ();" Useubmitbehavior = "false" runat = "server" />  

Set button type to false to change button

I see that your sample is working properly, also type

function myFunction () {var table = document.getElementById (" myTable "); Var line = table.insertRow (0); Var cell1 = row.insertCell (0); Var cell 2 = Row.Intel (1); Cell1.innerHTML = "new cell 1"; Cell2.innerHTML = "new cell 2"; }
  & lt; Table id = "myTable" & gt; & Lt; TR & gt; & Lt; Td> Row 1 cell1 & lt; / Td> & Lt; Td> Row1 cell2 & lt; / Td> & Lt; / TR & gt; & Lt; TR & gt; & Lt; Td> Row 2 cell 1 & lt; / Td> & Lt; Td> Row 2 cell 2 & lt; / Td> & Lt; / TR & gt; & Lt; TR & gt; & Lt; Td> Row 3 cell 1 & lt; / Td> & Lt; Td> Cry 3 cell 2 & lt; / Td> & Lt; / TR & gt; & Lt; / Table & gt; & Lt; Br> & Lt; Button onclick = "myfunction ()" & gt; Try it & lt; / Button & gt;  


Comments