Avatar of OB1Canobie
Flag 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">
    <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'); 


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

Visual Basic ClassicASP.NETJavaScript

Avatar of undefined
Last Comment

8/22/2022 - Mon

Log in or sign up to see answer
Become an EE member today7-DAY FREE TRIAL
Members can start a 7-Day Free trial then enjoy unlimited access to the platform
Sign up - Free for 7 days
Learn why we charge membership fees
We get it - no one likes a content blocker. Take one extra minute and find out why we block content.
Not exactly the question you had in mind?
Sign up for an EE membership and get your own personalized solution. With an EE membership, you can ask unlimited troubleshooting, research, or opinion questions.
ask a question
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.

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 () {

Open in new window

This is the best money I have ever spent. I cannot not tell you how many times these folks have saved my bacon. I learn so much from the contributors.

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