Jump to content
Xtreme .Net Talk

Recommended Posts

Posted

Hi,

 

How do I call a javascript function from ASP.Net (VB) code?

 

I added a javascript file into the asp.net project and wrote some javascript statements to display an IFrame.

 

The javascript function in the jscript file is:

 

<script language = "javascript">

 

function showIFrame()

{

var iframe = document.createElement("iframe");

 

iframe.id = "testiframe";

iframe.name = "testiframe";

iframe.frameborder = 1;

iframe.height = 185;

iframe.width = 175;

iframe.src = "C:\Documents and Settings\RadioButtons\Office.jpg";

window.document.body.appendChild(iframe);

 

return false;

 

}

 

How do I call this function from ASP.Net(VB) code? :)

e.g Form1_Load(.....)

Posted

Hi,

 

You have to register a startup script using Page.RegisterStartupScript.

This is how I show alert boxes from my asp.net code.

 

Sub ShowMessage(message As String)

Dim sb As New System.Text.StringBuilder("")

With sb

.Append("<script language='JavaScript'>")

.Append("ShowMessage(""" & message & """);")

.Append("</script")

.Append(">")

End With

Page.RegisterStartupScript("ShowMessage", sb.ToString())

End Sub

 

<script language="javascript">

<!--

function ShowMessage(text) {

alert(text);

return false;

} //-->

</script>

 

Hope this helps.

Posted
Why, why, why? Why would you call it from form load as opposed to the onload event of the document? You are not passing in any information, it's pointless.
Posted

Thanks both for the replies :)

 

I used the form_load method because the javascript has to execute when the page loads up.

 

Today I just discovered that there's a Page_Load method also.

 

so what is the difference between form and page load methods for an asp.net webpage?

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...