Jump to content
Xtreme .Net Talk

Recommended Posts

Posted

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?

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...