0

Hi guys,
First of all im trying to debug an application which has been already developed by someone else.
I have a form which has a few fields. there is a save button next to it which saves the data (this already works correctly)

The issue is that if I edit data in the fields and click somewhere else on the page then it allows the user to navigate without asking to save the data. ( Basically I want a pop up message saying 'do u want to save data ? ' with OK and Cancel button and when clicked on OK it first saves and navigates

var isDirty = false;

function setDirty(changeVal)
{
isDirty=changeVal;
}

window.onbeforeunload = checkExit;

function checkExit()
{
if(isDirty == true)
{
return confirmExit();

}
}
function confirmExit()
{
var answer = confirm("do you want to save record?");
if (answer){
__doPostBack('RememberTreeNodeState()','OnClientCl ick');
}

}

AND THEN USE THIS AS :

private TextBox AddTextBox(string strID, object strValue, bool bolDisabled)
{
TextBox txtBox = null;

Control ctlCurrentCtl = tblTree.FindControl(strID);
if (ctlCurrentCtl != null)
{
txtBox = (TextBox)ctlCurrentCtl;
}
else
{
txtBox = new TextBox();
}

try
{
txtBox.Text = Convert.ToString(strValue);
}
catch { }
txtBox.ID = strID;
txtBox.Width = Unit.Pixel(CONST_VALUE_FIELDWIDTH - 10);
txtBox.ReadOnly = bolDisabled;

if (this.Parent.FindControl("lblSaveMsg") != null)
{
//txtBox.Attributes.Add("onchange", "document.getElementById('" + this.Parent.FindControl("lblSaveMsg").ClientID + "').innerText = 'Note: You have unsaved changes';");
txtBox.Attributes.Add("onchange", "setDirty(true);"); 
}

Edited by __avd: Keep it Clear.

2
Contributors
1
Reply
2
Views
7 Years
Discussion Span
Last Post by ollystretton
0

If you have a <form> tag wrapping the form could you add an onblur attribute which calls the checkExit() function when the form loses focus?

Not tested but something like...

form1.Attributes.Add("onblur", "return checkExit();");

Edited by ollystretton: wrong function call

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.