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

Execute onload javascript function of user control when control is dynamically loaded within a radajaxpanel.

2 Answers 808 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
Aaron
Top achievements
Rank 1
Aaron asked on 23 Dec 2011, 06:54 PM

I currently have a page that dynamically loads a user control when a button click is executed.  The user control is placed on the page and loaded within a radajaxpanel.  I need to run a javascript function at the completion of the user control being loaded that accesses controls within that user control.  I have tried a few different ways to get this to happen, but I am unable to get it to work.

What does work is when I remove the radajaxpanel and then at the bottom of the ascx page I include the javascript function that I want to run followed by window.onload = functionToRun, but then I get the page reload etc. 

I have tried to register the script at prerender, and also tried the following in the Page_PreRender of the user control to run the desired function:

 

System.Web.UI.

 

Page page = (System.Web.UI.Page)this.Page;

 

 

 

MasterPage mp1 = (MasterPage)page.Master;

 

 

 

RadAjaxManager ajm = mp1.FindControl("RadAjaxManager1") as RadAjaxManager;

 

 

 

string script = String.Format("functionToRun();");

 

ajm.ResponseScripts.Add(script);

It finds the objects it needs within the codebehind, but then cannot find the functionToRun when it is time to run the client side function.

Is there a post or article that describes the best way to run a client side function once a dynamically loaded user control has finished loading within a RadAjaxPanel?

Thank you,

Aaron

2 Answers, 1 is accepted

Sort by
0
Aaron
Top achievements
Rank 1
answered on 09 Jan 2012, 08:51 PM
Hi just wondering if anyone had any ideas about this post?

Thank you.
0
Antonio Stoilkov
Telerik team
answered on 12 Jan 2012, 04:36 PM
Hi Aaron,

I have assembled a sample project demonstrating the desired functionality. You could achieve your scenario by adding JavaScript code in the user control placing it in pageLoad function and wrapping it with RadScriptBlock. Another possible solution is registering the script with Page.RegisterClientScriptBlock method as it is shown below.
Page.RegisterClientScriptBlock("scriptKey", "functionToRun();");

Greetings,
Antonio Stoilkov
the Telerik team
If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to their blog feed now
Tags
General Discussions
Asked by
Aaron
Top achievements
Rank 1
Answers by
Aaron
Top achievements
Rank 1
Antonio Stoilkov
Telerik team
Share this question
or