I am using asp.net post back method to send data from jQuery MessageBox to server. Is this correct way to send data to server without refreshing whole web page? What would be other alternatives?
default.aspx client code
function confirmDelete(id) {
var msg = 'Are you sure you want to delete user?';
$.msgbox(msg, {
type: "confirm",
buttons: [
{ type: "submit", value: "Yes" },
{ type: "submit", value: "No" }
]
},
function (res) {
var answ = res;
if (answ == 'Yes') {
__doPostBack('<%=upPanel.UniqueID%>$Delete', id);
}
});
return false;
}
default.aspx.cs server code
protected void Page_Load(object sender, EventArgs e)
{
if (IsPostBack && !IsCallback)
{
var sourceId = Request.Form.Get(postEventSourceID);
var argumentId = Request.Form.Get(postEventArgumentID);
if (sourceId.Contains("Delete"))
{
var id = Helpers.GetInt(argumentId);
DeleteUser(id);
}
}
}
You should use jquery ajax to partially refresh the page.
__doPostBackwill submit the form and refresh the whole page.