ScriptManager.RegisterStartupScript and the RadAjaxPanel

7 posts, 0 answers
  1. Kevin Schneider
    Kevin Schneider avatar
    48 posts
    Member since:
    Jan 2008

    Posted 12 Jan 2009 Link to this post

    Hello,

    I am in the process of building a control that registers some javascript after each postback (regular or ajax).  This is done in the PreRender event of the control and looks something like this:

    ScriptManager.RegisterStartupScript(thisthis.GetType(), this.ClientID + "_SplitterBarStartupScript", sb.ToString(), true);  
     

    This works fine both when using no Ajax panel at all and also when using the ASP.NET UpdatePanel.  After each postback the script is injected correctly and runs.  This doesn't work with the RadAjaxPanel though.

    I did some testing and found that RegisterClientScriptBlock does fire with the RadAjaxPanel after each postback.  I do not want to use this however because the script is injected before the elements have been loaded (too early).

    I have also seen suggestions on the forum to use the RadAjaxPanel's ClientScripts collection.  This will also not work for me because this is a custom control and doesn't know what other controls are included on the page.

    I would like this to work in all 3 scenarios: regular postback, ASP.NET UpdatePanel and RadAjaxPanel.

    Please advise as to how I should proceed.

    Thanks,
    Kevin
  2. Rosen
    Admin
    Rosen avatar
    3237 posts

    Posted 13 Jan 2009 Link to this post

    Hello Kevin Schneider,

    In order scripts to be resolved correctly by RadAjax they should be register with the page instead with the control. Thus the register statement should look similar to the following:

    ScriptManager.RegisterStartupScript(this.Page, this.Page.GetType(), this.ClientID + "_SplitterBarStartupScript", sb.ToString(), true);      

    Please give it a try and let us now if this helps.

    Regards,
    Rosen
    the Telerik team

    Check out Telerik Trainer, the state of the art learning tool for Telerik products.
  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. Kevin Schneider
    Kevin Schneider avatar
    48 posts
    Member since:
    Jan 2008

    Posted 13 Jan 2009 Link to this post

    This corrected the issue, thanks for the help.
  5. Stuart Wachsberg
    Stuart Wachsberg avatar
    3 posts
    Member since:
    Dec 2008

    Posted 12 Mar 2009 Link to this post

    While Kevin's solution fixed your case, it is not a general solution.

    By registering the script with the page, the script will always be rendered after ajax, even when the control is not visible.

    This is why you can - and should according to MS -  register a script with the control that needs it. The fact that the Telerik RadAjaxPanel does not support this is in fact a bug.

    Try your original  scenario with an MS update panel, and it will work.

    I have many controls that must spew out script, but only when the control has been rendered to the client. The control itself has no idea if it is embedded  in an update panel or not, and no idea if it will be rendered to the client, so ScriptManager.RegisterClientScript is ideal. If only it worked properly with RadAjaxPanel.


  6. Rosen
    Admin
    Rosen avatar
    3237 posts

    Posted 13 Mar 2009 Link to this post

    Hi Stuart,

    Indeed the necessarily of register script through the  page is an limitation of the RadAjax implementation as there is not way to resolve the scripts which are register though the control itself.

    However this in the scenario in question actually should not be a problem if the control is outputting its scripts in its render stage for example, as most controls do.

    I hope this information is helpful.

    All the best,
    Rosen
    the Telerik team

    Instantly find answers to your questions on the new Telerik Support Portal.
    Check out the tips for optimizing your support resource searches.
  7. Stuart Wachsberg
    Stuart Wachsberg avatar
    3 posts
    Member since:
    Dec 2008

    Posted 13 Mar 2009 Link to this post

    Rosen,

    Your answer is indeed helpful.

    That said, I remind your developers to keep your products co-operating with the underlying infrastructure in expected fashion. Failing to do so results in needless expenditure of customer time,  undermining the mission of your company.

    Best regards, Stuart
  8. sahil
    sahil avatar
    35 posts
    Member since:
    Jul 2008

    Posted 18 Nov 2010 Link to this post

    Thanks for this, i problem is solved.
Back to Top
UI for ASP.NET Ajax is Ready for VS 2017