Results 1 to 7 of 7

Thread: Register javascript in codebehind is not working

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Jun 2007
    Posts
    241

    Thumbs up Register javascript in codebehind is not working

    Hi friends,

    I am using Asp.Net application. From my codebehind i call the javascript function. so i am using,

    Page.ClientScript.RegisterStartupScript(Me.GetType(), "onLoad", "showcontent()", True)

    Now i registered script.Now i call the function showcontent in my contentpage.


    <script type="text/javascript" language="javascript">
    //window.onLoad=showcontent();
    function showcontent()
    {
    alert("enter");
    }

    while my contentpage load, this script fire and give alert message.But it doesn't fire.It gives script error. ie

    "missing ;before statement.[Break on this error] showcontent()Sys.Application.initialize();\n

    This error is happened in firefox. Run in IE nothing happened. The script is not fired in IE. what is the problem? I cant find it.

    Please help me if u can.

    Hope ur's reply

    Thanks
    Failing to plan is Planning to fail

  2. #2
    Frenzied Member Fishcake's Avatar
    Join Date
    Feb 2001
    Location
    Derby, UK
    Posts
    1,092

    Re: Register javascript in codebehind is not working

    I can't see any reason why it isn't working. I'm assuming the missing closing tag </script> is just a typo or wasn't copied over.

    Where are you placing the javascript in your .aspx page and where are you calling RegisterStartupScript in your codebehind?

  3. #3
    I'm about to be a PowerPoster! mendhak's Avatar
    Join Date
    Feb 2002
    Location
    Ulaan Baator GooGoo: Frog
    Posts
    38,170

    Re: Register javascript in codebehind is not working

    showcontent()

    should be

    showcontent();

  4. #4

    Thread Starter
    Addicted Member
    Join Date
    Jun 2007
    Posts
    241

    Thumbs up Re: Register javascript in codebehind is not working

    s mendhak. Its right. I missed semicolon.
    Failing to plan is Planning to fail

  5. #5
    I'm about to be a PowerPoster! mendhak's Avatar
    Join Date
    Feb 2002
    Location
    Ulaan Baator GooGoo: Frog
    Posts
    38,170

    Re: Register javascript in codebehind is not working

    Add Resolved, you know the drill

  6. #6

    Thread Starter
    Addicted Member
    Join Date
    Jun 2007
    Posts
    241

    Thumbs up Re: Register javascript in codebehind is not working

    Page.ClientScript.RegisterStartupScript(Me.GetType(), "onLoad1", "DisplayDivTwo();", True)

    In the code First i didnt put semicolon DisplayDivTwo(). I Put DisplayDivTwo(); . I put now. It's working.

    But i got another problem now mendhak.

    ie., window.location="frmContentPageOne.aspx" It goes to this page while page load in firefox.But in IE its not working.

    I change the script window.location.href="frmContentPageOne.aspx". But it doesn't working.

    Hopes ur's reply.
    Failing to plan is Planning to fail

  7. #7
    I'm about to be a PowerPoster! mendhak's Avatar
    Join Date
    Feb 2002
    Location
    Ulaan Baator GooGoo: Frog
    Posts
    38,170

    Re: Register javascript in codebehind is not working

    It's single quote and a semicolon

    window.location.href='pagename.aspx';

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width