Hi,
I want to insert into database without refreshing page and it's done correctly but my problem is refreshing table that show the data after insertion without refreshing the whole page
I did html table in code behind and bind it to aspx page like this
<%= html %>
html is string Bulider that I draw my HTML table on it and fill it by database data
ok, after insertion by ajax here
$("[id*=btnSave]").bind("click", function () {
var user = {};
user.Username = $("[id*=txtUsername]").val();
user.Password = $("[id*=txtPassword]").val();
$.ajax({
type: "POST",
url: "CS.aspx/SaveUser",
data: '{user: ' + JSON.stringify(user) + '}',
contentType: "application/json; charset=utf-8",
dataType: "json",
success: function (response) {
//window.location.reload();
}
});
return false;
});
in saveUser function I call that function that rebuild HTML table in html string builder
but the last row I added doesn't appear in table until I refresh the page manually or I remove comment in this line
window.location.reload();
and this is my HTML table
html.Append("<table border = '1' id='myTable' class='tablesorter'>");
html.Append("<thead>");
html.Append("<tr>");
string name = "";
foreach (DataColumn column in dt.Columns)
{
html.Append("<th>");
html.Append(column.ColumnName);
html.Append("</th>");
}
html.Append("<th>");
html.Append("Delete");
html.Append("</th>");
html.Append("<th>");
html.Append("Update");
html.Append("</th>");
html.Append("</tr>");
html.Append("</thead>");
html.Append("<tbody>");
foreach (DataRow row in dt.Rows)
{
int i = 0;
html.Append("<tr>");
foreach (DataColumn column in dt.Columns)
{
html.Append("<td>");
html.Append(row[column.ColumnName]);
html.Append("</td>");
if(i == 0){
name = row[column.ColumnName].ToString();
}
i++;
}
html.Append("<td>");
html.Append("<input type='submit' value='Delete' class='btnDelete' id='" + name + "' >");
html.Append("</td>");
html.Append("<td>");
html.Append("<input type='submit' value='Update' class='btnPrepareToUpdate' id='update" + name + "'>");
html.Append("</td>");
html.Append("</tr>");
}
html.Append("</tbody>");
html.Append("</table>");
any help to refresh only HTML table ?