title: ASP.NET Changing Server IP Address and Redirect to Login Page
body: <p>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.  </p>
  
  <p>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? </p>
  
  <p>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.  </p>
  
  <p>Here is my code:</p>
  
  <pre><code>&lt;script type="text/javascript"&gt;
      function Logout () 
      {
          window.location.href = "Login.aspx";
      };
  &lt;/script&gt;
  
  
  &lt;asp:Label ID="dummyLabel" runat="server" /&gt;    
  &lt;asp:Panel ID="AlertBox" runat="server" Style="display: none;" CssClass="modalPopup"&gt;
      &lt;div style="border: 3px solid #000000"&gt;
          &lt;table style="background-color: #e3e2fe;"&gt;
              &lt;tr&gt;
                  &lt;td align="center"&gt;
                      &lt;div id="divCEMsg" runat="server" style="text-align: left; width: 300px; margin-left:5px;"&gt;
                          &lt;asp:Label ID="Label34" runat="server" Text="You are changing the IP Settings so your current web browser session will be disconnected.&lt;br /&gt;&lt;br /&gt;To log back in you will need to use the newly assigned IP Address&lt;br /&gt;&lt;br /&gt;Click OK to proceed with network setting changes"&gt;&lt;/asp:Label&gt;
                      &lt;/div&gt;
                      &lt;br/&gt;&lt;br/&gt;
                  &lt;/td&gt;
              &lt;/tr&gt;
  
              &lt;tr&gt;                
                  &lt;td align="center"&gt;
                      &lt;asp:Button ID="btnOk" runat="server" Text="OK" OnClientClick="Logout();" onclick="btnOk_Click" &gt;&lt;/asp:Button&gt;
                  &lt;/td&gt;
              &lt;/tr&gt;
          &lt;/table&gt;
      &lt;/div&gt;
  &lt;/asp:Panel&gt;
  &lt;ajaxToolkit:ModalPopupExtender ID="ModalPopupExtender1" runat="server" 
      PopupControlID="AlertBox" BackgroundCssClass="modalBackground" DropShadow="true" TargetControlID="dummyLabel"&gt;
  &lt;/ajaxToolkit:ModalPopupExtender&gt;
  
  
  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;
          }
      }
  }
  </code></pre>