Link to home
Start Free TrialLog in
Avatar of OB1Canobie
OB1CanobieFlag for United States of America

asked on

Execute javascript at load with page

I have  an page programmed in vb.  I'm trying to call the javascript located in the head of the page "goNewWin()".  I'm having trouble with the syntax for the codebehind.  I've attached the javascript at the top of the aspx page and the codebehind code.  Thanks.
--aspx page code--
<head runat="server">
    <link href="style.css" rel="stylesheet" type="text/css" />
<script type="text/javascript">
    function goNewWin() {


--vb code behind--
    Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

        If Page.IsPostBack = False Then
            If Session("Logged_In") Is Nothing Then

            End If
        End If

    End Sub

Open in new window

Avatar of TomKnox
Flag of Germany image

Link to home
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Amandeep Singh Bhullar
try calling the function, before the ending of form tag, let all the controls load.

<script type='text/javascript'>
If you want to execute goNewWin() every time the page loads then what TomKnox suggested makes sense. But if you want to set it conditionally then you may use Page.RegisterStartupScript.
Avatar of CahitEy

Try to use Jquery :) that executes js after page complete, you are facing with error because of render order of
for add jquery to your page

 <script type="text/javascript" src=""></script>  

add this line to your head title or download to your root folder and call from there

        $(document).ready(function () {

Open in new window

Avatar of OB1Canobie


Thanks. The code worked when I used code behind and add and attribute to the body.