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

asked on

Execute javascript at load with asp.net page

I have  an asp.net page programmed in vb.  I'm trying to call the javascript located in the head of the asp.net 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">
    <title>Home</title>
    <link href="style.css" rel="stylesheet" type="text/css" />
<script type="text/javascript">
    function goNewWin() {
    TheNewWin =window.open("music.html",'TheNewpop','toolbar=1,location=1,directories=1,status=1,menubar=1,scrollbars=1,resizable=1'); 
    TheNewWin.blur();
    }
</script> 

</head>

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

ASKER CERTIFIED SOLUTION
Avatar of TomKnox
TomKnox
Flag of Germany image

Link to home
membership
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'>
goNewWin();
</script>
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
CahitEy

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


 <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.min.js"></script>  

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

        $(document).ready(function () {
goNewWin();
}

Open in new window

Avatar of OB1Canobie

ASKER

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