Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Call a javascriptfunction in PageLoad event

Posted on 2004-10-26
7
Medium Priority
?
2,142 Views
Last Modified: 2008-02-01
How can I call a javascript function in my codebehind PageLoad event???
0
Comment
Question by:Marcelo_Rodosis
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
7 Comments
 
LVL 18

Expert Comment

by:tusharashah
ID: 12409960
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
 
LVL 22

Expert Comment

by:CJ_S
ID: 12410001
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
 
LVL 17

Expert Comment

by:AerosSaga
ID: 12410004
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
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 

Author Comment

by:Marcelo_Rodosis
ID: 12412635
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
 
LVL 18

Accepted Solution

by:
tusharashah earned 500 total points
ID: 12412714
Just add following code in your Page_Load

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

-tushar
0
 

Author Comment

by:Marcelo_Rodosis
ID: 12412770
Yes, it works !!!
And I'm sufering because a sigle line of code!!!
hehehehhehe

thanks  tusharashah
you got the points
0
 
LVL 18

Expert Comment

by:tusharashah
ID: 12412803
Nice to have you going Marcelo!

Thanks for A

-tushar
0

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

IntroductionWhile developing web applications, a single page might contain many regions and each region might contain many number of controls with the capability to perform  postback. Many times you might need to perform some action on an ASP.NET po…
International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
Visualize your data even better in Access queries. Given a date and a value, this lesson shows how to compare that value with the previous value, calculate the difference, and display a circle if the value is the same, an up triangle if it increased…
This lesson discusses how to use a Mainform + Subforms in Microsoft Access to find and enter data for payments on orders. The sample data comes from a custom shop that builds and sells movable storage structures that are delivered to your property. …
Suggested Courses

618 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question