
April 20, 2012 07:07 by
using jquery and telerik ajax manager I was able to add a dirty check to the imput controls.
1. ascx page with dynamic controls loading in a place holder.
2. Add jQuery code to add the change function. but code on bottom of ascx page.
<script type="text/javascript">
var _isDirty = false;
$(":input").change(function () {
setDirty();
});
// checks to see if form is dirty before leaving page.
//close, update and cancel buttons will set the isDirty to 0 to avoid alert .
$(window).bind('beforeunload', function () {
checkSave();
}
);
var isDirty;
isDirty = 0;
function setDirty() {
isDirty = 1;
}
function checkSave() {
var sSave;
if (isDirty == 1) {
sSave = window.confirm("You have some changes that have NOT been saved. Click OK to save now or CANCEL to continue without saving.");
if (sSave == true) {
$find("<%= RadAjaxManager1.ClientID %>").ajaxRequest("Save");
} else {
return true;
}
}
}
</script>
3 telerik ajax manager
<telerik:RadAjaxManager ID="RadAjaxManager1" runat="server"
onajaxrequest="RadAjaxManager1_AjaxRequest">
</telerik:RadAjaxManager>
4. cs code behind for ajax request
protected void RadAjaxManager1_AjaxRequest(object sender, Telerik.Web.UI.AjaxRequestEventArgs e)
{
if (e.Argument == "Save")
{
SaveData();
}
}
5. page load to set some buttons to set isDirty back to 0
protected void Page_Load(object sender, EventArgs e)
{
ibUpdate.Attributes.Add("onclick", "isDirty = 0;");
ibCancel.Attributes.Add("onclick", "isDirty = 0;");
}
6f151221-c91d-4ed4-b09c-a82d8e295c3d|1|5.0