scatman scatman - 2 years ago 70
Javascript Question

Calling a javascript function from Page_Load in code-behind

How can I call a javascript function, that is in the aspx page, from the Page_Load method, in the code-behind?

Answer Source

The easiest way is to use the page's ClientScript property. You can register some code to run when the page loads using something like

ClientScript.RegisterStartupScript(GetType(), "hiya", "alert('hi!')", true);

See for more info.

This should be available from a child control by tacking "Page." onto the beginning of the code above.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download