Close form after buttonclick
-
Hello, I am trying to close a form after a button click event, but I need it to run some code first. I know about
OnClientClick="javaScript:window.close(); return false;"
and that successfully closes the window, but I need to be able to run some code behind in C# before that executes. I currently have this for my button: It asks if I want to close the window, but never gets to the onclick event. Does anyone have any ideas? Thanks for your time. JMJohn Michael
-
Hello, I am trying to close a form after a button click event, but I need it to run some code first. I know about
OnClientClick="javaScript:window.close(); return false;"
and that successfully closes the window, but I need to be able to run some code behind in C# before that executes. I currently have this for my button: It asks if I want to close the window, but never gets to the onclick event. Does anyone have any ideas? Thanks for your time. JMJohn Michael
A common approach for this is using AJAX to make the server call prior to closing the window
only two letters away from being an asset
-
A common approach for this is using AJAX to make the server call prior to closing the window
only two letters away from being an asset
-
If you've got the time, could you give me a quick example on how to do this, or where I can find an example? I havent really used AJAX much. Thanks! BTW, The code behind is in C#.
John Michael
If you haven't used AJAX then it would be pointless to give code you wouldn't understand. Read up on it, then come back and ask if you don't understand.
only two letters away from being an asset
-
Hello, I am trying to close a form after a button click event, but I need it to run some code first. I know about
OnClientClick="javaScript:window.close(); return false;"
and that successfully closes the window, but I need to be able to run some code behind in C# before that executes. I currently have this for my button: It asks if I want to close the window, but never gets to the onclick event. Does anyone have any ideas? Thanks for your time. JMJohn Michael
I would suggest you to follow the approach explained by jhon. if you are not familiar with AJAX then you can follow this general approach like write javascript code from server side after postback <asp:Button ID="btnVDistro" runat="server" Font-Bold="True" onclick="btnVDistro_Click" Text="Use Validated" /> protected void btnVDistro_Click(object sender, EventArgs e) { // Add your code here this.ClientScript.RegisterStartupScript(this.GetType(), "close", "javaScript:window.close(); return false;, true); }