How to execute javascript when the Page Loads?

LiLo

Freshman
Joined
Mar 10, 2006
Messages
33
Hi, :D

How to execute a javascript function when the asp.net webpage is first loaded? or refreshed?

Currently, I put the javascript function in the Page_Load Method. Visual Studio 2005 is used. The asp.net language is in vb.

Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load

Page.RegisterStartupScript("MyScript", _
"<script language = 'javascript'>" & _
"function showIFrame(){" & _
"var iframe = document.createElement('iframe');" & _
"iframe.ID = 'testiframe';" & _
"iframe.name = 'testiframe';" & _
"iframe.frameborder = 1;" & _
"iframe.style.top = 200;" & _
"iframe.width = 175;" & _
"iframe.scrolling = 'auto';" & _
"iframe.src = 'C:\Test.html';" & _
"window.document.body.appendChild(iframe);" & _
"return false;" & _
"}" & _
"</script>")

Button1.Attributes("onClick") = "return showIFrame()"

End Sub

The jscript above can correctly display an IFrame when the button is clicked. But how to make the javascript execute by itself when the webpage loads?
 
Hi,

Thank you for the reply.

I used the window.onload javascript method and it can work too :)
 
Back
Top