Technologies:
Tolerim
a month ago
On button click in VBnet, how can I execute a codebehind function before opening a modal dialog?
Answers(2)
Vogi
a month ago
Verified Answer
You can use the ClientScript.RegisterStartupScript method in code behind to execute JavaScript functions after running the codebehind. Here is an example of how to use it:
protected void Button1_Click(object sender, EventArgs e)
{
// Your codebehind function here
// ...
// Register the script to execute after the codebehind function
string script = "alert('Hello!');";
ClientScript.RegisterStartupScript(this.GetType(), "alert", script, true);
}
You can replace the alert('Hello!'); with your own JavaScript function. This will execute after your codebehind function is complete.
I hope this helps! Let me know if you have any other questions.
Sources
c# - Calling JavaScript Function From CodeBehind - Stack OverflowRun JavaScript code or call a function after n secondsexecute javascript from code behind?How to call javascript function from code-behind - Stack OverflowCalling a code-behind function from JavaScript - CodeProjectTolerim
a month ago
It sounds like you're trying to execute a JavaScript function after completing some server-side processing. One way to achieve this is to use the Page.ClientScript.RegisterStartupScript method to register a JavaScript function to be executed on the client side after the code behind has completed its processing.
First, create a JavaScript function that triggers the modal popup, for example:
function openModalPopup() {
var modalPopup = $find("ModalPopupExtender1");
modalPopup.show();
}
Then, in your code behind, call RegisterStartupScript to register this function to be executed on the client side:
ScriptManager.RegisterStartupScript(this, GetType(), "openModalPopup", "openModalPopup();", true);
This will execute the openModalPopup function on the client side, which will show the modal popup.
Make sure that the ID of your ModalPopupExtender is "ModalPopupExtender1", or replace it with the appropriate ID in your JavaScript function.