marknery
marknery

Reputation: 1543

Calling a javascript function after a server call in asp.net web forms

Is there a way in web forms to call a javasctipt function after making a server call for example

function showAlert(){ 
   alert("hello");
}


 <asp:Button ID="callJavasctips" runat="server" Text="callJavasctipt" OnClick="callJavaSctipt_click" />  

In MVC I can say OnSuccess = "showAlert()" is there a way to do this in webforms?

UPDATE

I ended up using ScriptManager instead of Page.ClientScript because it didn't work with update panels.

Upvotes: 0

Views: 3866

Answers (2)

Hasan Fahim
Hasan Fahim

Reputation: 3885

In the callJavaSctipt_click event in the code behind, do the following:

Page.RegisterClientScriptBlock("MyScript","<SCRIPT Language='JavaScript'> alert('Hello'); </SCRIPT>");

Upvotes: 0

Bala R
Bala R

Reputation: 108957

For calling javascript after, you'll have to use ClientScriptManager.RegisterStartupScript() on your button's click handler.

I'm not sure if you would be interested in this, but you can define onclientclick="some_javascript_snippet" for <asp:Button /> but it's called before the server side handler.

Upvotes: 1

Related Questions