After days of researching my issue, I am still struggling to get it working correctly. Although I have found some helpful information related to my problem, I seem to have hit a roadblock and could really use some guidance.
I developed a small .NET 3.5 VB.NET web application that allows users to manage certain data through 3 pages. One aspect of the requirements that I wasn't entirely happy with was the user's request to make all changes and then save them collectively using a save button, rather than saving after each modification to the grid.
To address this, I decided to utilize a session object to store a collection of objects on each page. My aim is to trigger a dialog whenever a user tries to alter the value of a dropdown or navigate away from the page while there are pending actions. After extensive research, I chose to create a hidden field on the page and update its value each time an action is updated on the server side. Then, based on the value of the hidden field, I intend to prompt the user to save their changes if necessary.
Here is the JavaScript function I implemented:
<telerik:RadCodeBlock ID="RadCodeBlock2" runat="server">
<script type="text/javascript>
window.onbeforeunload = confirmExit;
function confirmExit()
{
var actionCount = $get('<%=ActionCounterField.ClientID %>').value;
if (actionCount > 0) {
alert("Pending Changes!");
}
}
</script>
</telerik:RadCodeBlock>
The declaration of the hidden field:
<asp:HiddenField id="ActionCounterField" runat="server" />
And here is my server-side code:
Protected Sub UpdateActionCount()
ActionCounterField.Value = GoalCategoryActionList.Count
End Sub
While debugging the application and adding a record to the grid, the server-side code functions as intended. Furthermore, I have confirmed that the javascript function can locate the hidden control. However, I am perplexed as to why the function cannot retrieve the value stored in the hidden field.
Any assistance would be greatly appreciated. Thank you!