This is a migrated thread and some comments may be shown as answers.

ScriptManager.RegisterStartupScript and the RadAjaxPanel

6 Answers 927 Views
Ajax
This is a migrated thread and some comments may be shown as answers.
Kevin Schneider
Top achievements
Rank 1
Kevin Schneider asked on 12 Jan 2009, 09:46 PM
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

6 Answers, 1 is accepted

Sort by
0
Rosen
Telerik team
answered on 13 Jan 2009, 07:14 AM
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.
0
Kevin Schneider
Top achievements
Rank 1
answered on 13 Jan 2009, 04:37 PM
This corrected the issue, thanks for the help.
0
Stuart Wachsberg
Top achievements
Rank 1
answered on 12 Mar 2009, 09:54 PM
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.


0
Rosen
Telerik team
answered on 13 Mar 2009, 11:43 AM
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.
0
Stuart Wachsberg
Top achievements
Rank 1
answered on 13 Mar 2009, 01:38 PM
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
0
sahil
Top achievements
Rank 1
answered on 18 Nov 2010, 08:49 AM
Thanks for this, i problem is solved.
Tags
Ajax
Asked by
Kevin Schneider
Top achievements
Rank 1
Answers by
Rosen
Telerik team
Kevin Schneider
Top achievements
Rank 1
Stuart Wachsberg
Top achievements
Rank 1
sahil
Top achievements
Rank 1
Share this question
or