<script language="javascript" type="text/javascript">
window.onbeforeunload = saveChanges;
function saveChanges()
{
var changes = document.getElementById("<%=this.ButtonSubmit.ClientID%>").disabled;
if(!changes)
{
event.returnValue = 'Changes were not saved. Click Cancel to go back and submit changes, or click OK to continue.';
}
}
function enableSubmit()
{
document.getElementById("<%=this.ButtonSubmit.ClientID%>").disabled = false;
}
</script>
The first function: saveChanges() is called when ever the user tries to change the current page or close the browser. It just asks if they user wants to leave without saving.
The second function is called when ever a textbox, or other asp/html control has changed. This basically just enables the submit button.
So, within the page we might have a ASP.Net control like this:
<asp:textbox id="TextBox1" runat="server" onchange="enableSubmit()" width="49px"><asp:textbox>
Now, you would end up getting a warning in ASP.Net since it doesn't recognize the onchange event, since this is actually a javascript event. The trick here is when the page is render this is how it would look in the html:
<input id="ctl00_ContentPlaceHolder1_TextBox1" style="WIDTH: 49px" onchange="enableSubmit()" name="ctl00$ContentPlaceHolder1$TextBoxNotes">
No comments:
Post a Comment