BreakHead
BreakHead

Reputation: 10672

How to call a JavaScript function from C# code

I need to call a javascript function from C# code after page Load, or is it there any way that I can do this on .aspx page itself??

Thanks

Upvotes: 2

Views: 1138

Answers (3)

Carlos Muñoz
Carlos Muñoz

Reputation: 17844

string script = "..." // your script here without <script> tags
ClientScript.ClientScript.RegisterStartupScript(GetType(), "key", script, true) 

Also if you want to use it directly from the .aspx you can use jquery

$(document).ready( function() {
    //... your script here
});

Upvotes: 1

ACP
ACP

Reputation: 35264

You can use this,

Page.ClientScript.RegisterStartupScript(Page.GetType(), "script", 
   "urfunction()", true);

Upvotes: 1

anishMarokey
anishMarokey

Reputation: 11397

try with RegisterStartupScript

E.g:

 RegisterStartupScript("Msg1", "<script language='javascript'> alert('Hello World')  </script>");

Upvotes: 2

Related Questions