For this we can utlize a nice little jQuery plugin called DirtyForm
Download dirty form:
Download jQuery:
Example:
<%@ Page Language="C#" %> <html> <head id="Head1" runat="server"> <script src="Scripts/jquery-1.4.1.min.js" type="text/javascript"></script> <script src="Scripts/jquery-dirtyform.js" type="text/javascript"></script> <script language="javascript" type="text/javascript"> var isDirty = false; $(document).ready(function () { $('#<%= this.Form.ClientID %>') .dirty_form() .dirty(function (event, data) { isDirty = true; }); }); function Save() { if (!isDirty) { alert("You didn't change anything"); return false; } return true; } </script> <script runat="server"> protected void Save(object sender, EventArgs e) { this.lblUpdateTime.Text = string.Format("Last Updated On: {0}", DateTime.Now.ToString("hh:mm:ss")); } </script> </head> <body> <form id="form1" runat="server"> <asp:TextBox runat="server" ID="txtName"></asp:TextBox><br /> <asp:TextBox runat="server" ID="txtAddress"></asp:TextBox><br /> <asp:TextBox runat="server" ID="txtPostcode"></asp:TextBox><br /> <asp:TextBox runat="server" ID="txtEmail"></asp:TextBox><br /> <asp:Button runat="server" ID="btnSave" OnClick="Save" OnClientClick="return Save();" Text="Save" /><br /> <asp:Label runat="server" ID="lblUpdateTime" /> </form> </body> </html>
No comments:
Post a Comment