Marcelo_Rodosis
asked on
Call a javascriptfunction in PageLoad event
How can I call a javascript function in my codebehind PageLoad event???
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( "clientScr ipt"))
RegisterStartupScript ("clientScript", scriptString)
End If
End Sub
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(
RegisterStartupScript ("clientScript", scriptString)
End If
End Sub
Dim popupScript As String = "<script language='javascript'>" & _
"window.open('PopUp.aspx', 'CustomPopUp', " & _
"'width=200, height=200, menubar=yes, resizable=no')" & _
"</script>"
Page.RegisterStartupScript ("PopupScr ipt", popupScript)
"window.open('PopUp.aspx',
"'width=200, height=200, menubar=yes, resizable=no')" & _
"</script>"
Page.RegisterStartupScript
ASKER
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 :myFunctio n()")
but it doesn't work, and I have tried I lot of alternatives....
function myFunction() {
.
.
.
}
and in pageload event i need to call this function, as something like this:
Response.Write("javascript
but it doesn't work, and I have tried I lot of alternatives....
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Yes, it works !!!
And I'm sufering because a sigle line of code!!!
hehehehhehe
thanks tusharashah
you got the points
And I'm sufering because a sigle line of code!!!
hehehehhehe
thanks tusharashah
you got the points
Nice to have you going Marcelo!
Thanks for A
-tushar
Thanks for A
-tushar
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 IsClientScriptBlockRegiste
RegisterClientScriptBlock(
End If
End Sub
OR
You can simply call the function using <body onLoad="YourFunctionName()
-tushar