ScriptManager.RegisterStartupScript doest not put the code in the correct page

Last post 02-04-2009 9:00 PM by Vince Xu - MSFT. 4 replies.

Sort Posts:

  • ScriptManager.RegisterStartupScript doest not put the code in the correct page

    01-30-2009, 5:08 PM
    • Member
      point Member
    • dotnetsurfer
    • Member since 01-30-2009, 9:56 PM
    • Posts 2

    Hi,

    I have an problem to execute javascript from asp.net (c# code). I have a page1.aspx that load a usercontrol ctrl.ascx. This control does an ajax request, by loading another page2.aspx, to compute some thing. The html content of page2.aspx is loaded in a div of page1.aspx. The page2.aspx load an userControl where I call ScriptManager.RegisterStartupScript(this, typeof(System.Web.UI.Page), "MyKey", myscript, true).

    The problem is that the javascriptscript code is added in the page2.aspx, so it is never executed. I don't have an updatePanel in my page1.aspx, and I can't modify it because i must modify a big project.

    Can you help me please, if someone has a solution ?

    Thanks.

  • Re: ScriptManager.RegisterStartupScript doest not put the code in the correct page

    01-30-2009, 7:45 PM
    • All-Star
      36,024 point All-Star
    • rtpHarry
    • Member since 10-01-2006, 8:51 AM
    • Lincoln, England
    • Posts 5,816

     From looking here:

    It would seem that the first "this" in the RegisterStartupScript you give in your question is a reference to a page to add it to.

    If this is the case then you will need to pass in a reference to your master page.

     

    I dont know about the execution order but you probably need to do this early on in the cycle like in page_init or something before page is generated.

     

    This might not be possible because I dont know without looking it up what stage of the page lifecyle that usercontrols are created compared to what you want to do.

  • Re: ScriptManager.RegisterStartupScript doest not put the code in the correct page

    02-03-2009, 2:25 AM

    Hi,

    After the JavaScript code is registered to the client. After you recieve the HTML via XmlHttpRequest, it will be recieved in page1.aspx. Please check if the source code has contained these JavaScript code in related div in page1.aspx via some tool. But you can only register a client method so that you can call it in page1.aspx.

     

     


    Vince Xu
    Microsoft Online Community Support
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.
  • Re: ScriptManager.RegisterStartupScript doest not put the code in the correct page

    02-04-2009, 8:57 AM
    • Member
      point Member
    • dotnetsurfer
    • Member since 01-30-2009, 9:56 PM
    • Posts 2

    Hi,

    I already checked the source code of page1, the javascript code is not registred. In the place where i execute ScriptManager.RegisterStartupScript, i put a brekpoint and i saw that the script is registred in page2.

    Thanks.

  • Re: ScriptManager.RegisterStartupScript doest not put the code in the correct page

    02-04-2009, 9:00 PM
    Answer

    Hi, 

    Did the script code rendered on page2 was not recieved by page1? I doubt the parser in page1 recieved HTML but script code.

    If so, then we are not able to do anything for this unless you modify the parser or load script reference in page1.

     


    Vince Xu
    Microsoft Online Community Support
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.
Page 1 of 1 (5 items)