I am creating a web application in ASP.NET/C# that allows users to remotely manage a small Panel PC (the server). One of the requirement is to provide the ability for the user to change all of the network related settings of the Ethernet port on the Panel PC. This would include IP Address, Sub Net Mask, Default Gateway and DNS servers. So if the user changes a setting (like the IP Address or Default Gateway) that will most likely terminate their current browser session, I want to display a dialog box letting them know that their current session will (or has) ended and then redirect them to the login page again.
I have tried using the AJAX ModalPopup, where the onClick event of the dialog box OK button, executes the necessary server side (C#) code to change the actual network settings and the OnClientClick property is set to call a javascript function to redirect to the login page again. The redirect is working but the onClick code behind isn't getting called. I've been looking into using Page.ClientScript.RegisterStartupScript() but I'm not sure whether that will work in this case and if so where in my code behind would it go?
I'm not 100% sure the way I'm trying to implement this is the best way or if it's even possible to do what I want this way. I'm open to any options or suggestions.
Here is my code:
<script type="text/javascript">
function Logout ()
{
window.location.href = "Login.aspx";
};
</script>
<asp:Label ID="dummyLabel" runat="server" />
<asp:Panel ID="AlertBox" runat="server" Style="display: none;" CssClass="modalPopup">
<div style="border: 3px solid #000000">
<table style="background-color: #e3e2fe;">
<tr>
<td align="center">
<div id="divCEMsg" runat="server" style="text-align: left; width: 300px; margin-left:5px;">
<asp:Label ID="Label34" runat="server" Text="You are changing the IP Settings so your current web browser session will be disconnected.<br /><br />To log back in you will need to use the newly assigned IP Address<br /><br />Click OK to proceed with network setting changes"></asp:Label>
</div>
<br/><br/>
</td>
</tr>
<tr>
<td align="center">
<asp:Button ID="btnOk" runat="server" Text="OK" OnClientClick="Logout();" onclick="btnOk_Click" ></asp:Button>
</td>
</tr>
</table>
</div>
</asp:Panel>
<ajaxToolkit:ModalPopupExtender ID="ModalPopupExtender1" runat="server"
PopupControlID="AlertBox" BackgroundCssClass="modalBackground" DropShadow="true" TargetControlID="dummyLabel">
</ajaxToolkit:ModalPopupExtender>
protected void btnOk_Click(object sender, EventArgs e)
{
//save the settings to the database
if (saveSetupDataToDatabase())
{
//update the Panel PC network settings
if (!updatePanelPcNetworkSettings())
{
return;
}
}
}