Call a javascriptfunction in PageLoad event

How can I call a javascript function in my codebehind PageLoad event???
Marcelo_RodosisAsked:
Who is Participating?
 
tusharashahCommented:
Just add following code in your Page_Load

Page.RegisterStartupScript("Script", "<script>myFunction();</script>");

-tushar
0
 
tusharashahCommented:
You can use RegisterClientScriptBlock for this...

Sub Page_Load( sender as Object,e as EventArgs)
         
       'Form the script that is to be registered at client side.
        Dim scriptString as String = "<script language=JavaScript> "
        scriptString += "alert('Welcome to Microsoft .NET')<"
        scriptString += "/"
        scriptString += "script>"
     
            If(Not IsClientScriptBlockRegistered("clientScript"))
              RegisterClientScriptBlock("clientScript", scriptString)
            End If
     End Sub

OR

You can simply call the function using <body onLoad="YourFunctionName()">

-tushar
0
 
CJ_SCommented:
To be more specific you will need to use the

RegisterStartupScript and IsStartupScriptRegistered

Sub Page_Load( sender as Object,e as EventArgs)
         
       'Form the script that is to be registered at client side.
        Dim scriptString as String = "<script language=JavaScript> "
        scriptString += "alert('Welcome to Microsoft .NET')<"
        scriptString += "/"
        scriptString += "script>"
     
            If(Not IsStartupScriptRegistered("clientScript"))
              RegisterStartupScript ("clientScript", scriptString)
            End If
End Sub
0
Cloud Class® Course: Amazon Web Services - Basic

Are you thinking about creating an Amazon Web Services account for your business? Not sure where to start? In this course you’ll get an overview of the history of AWS and take a tour of their user interface.

 
AerosSagaCommented:
Dim popupScript As String = "<script language='javascript'>" & _
  "window.open('PopUp.aspx', 'CustomPopUp', " & _
  "'width=200, height=200, menubar=yes, resizable=no')" & _
  "</script>"

Page.RegisterStartupScript("PopupScript", popupScript)
0
 
Marcelo_RodosisAuthor Commented:
I think i should be more clear. My problem is: I have a javacsript function:

function myFunction() {
.
.
.
}

and in pageload event i need to call this function, as something like this:

Response.Write("javascript:myFunction()")

but it doesn't work, and I have tried I lot of alternatives....
0
 
Marcelo_RodosisAuthor Commented:
Yes, it works !!!
And I'm sufering because a sigle line of code!!!
hehehehhehe

thanks  tusharashah
you got the points
0
 
tusharashahCommented:
Nice to have you going Marcelo!

Thanks for A

-tushar
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.