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

Javascript in usercontrol shown in ajax request not seen

2 Answers 168 Views
Ajax
This is a migrated thread and some comments may be shown as answers.
rh
Top achievements
Rank 1
rh asked on 06 Jan 2008, 07:05 PM
I have a scenario where I have a usercontrol that is initially not visible on a page. If the user selects a certain option in a combo box then the user control is shown as part of an ajax request using RadAjaxManager Prometheus. This works and the user control is dynamically displayed on the page.

However, the user control contains some javascript that is specific to the controls within the user control. That is, it uses <%= SomeControl.ClientID %> within the javascript to get references to the controls within the user control. The problem is that the javascript isn't visible after displaying the user control. When I try to call functions that are contained within the user control I get an error that it can't find the function. How do I make the functions available after showing the user control as part of a ajax request?

2 Answers, 1 is accepted

Sort by
0
rh
Top achievements
Rank 1
answered on 06 Jan 2008, 11:41 PM
I've tried using the ResponseScripts collection of the RadAjaxManager but it isn't working. My script includes functions that then get called when an action occures (like a button click). I'm guessing maybe ResponseScripts is only for code to immediately run (like an alert box) and not for functions to be registered with the page to be called?

It is also unclear as to whether or not the script string should include the script tag.

The key to this not working is that the user control is initially not visible. If I make the user control initially visible then everything works fine because the javascript is parsed with the initial page load. But by loading the usercontrol as part of the ajax request then ASP.NET AJAX just shoves the javascript into the inner HTML of the control to update and doesn't register it with the page.

I haven't had any luck with the ResponseScripts of RadAjaxManger, Page.RegisterClientScriptBlock, or ScriptManager.RegisterClientScript block. Nothing seems to be able to parse the functions in my script and make them available on the page.
0
plamen
Top achievements
Rank 1
answered on 08 Jan 2008, 09:12 AM
hi rh

You can enclose this script in RadScriptBlock.


example:

.ascx

<telerik:RadScriptBlock ID="RadScriptBlock1" runat="server">

<script type="text/javascript">

function Click()

{

alert(

"test");

}

</script>

</telerik:RadScriptBlock>





Thank you...
<John:Peel />
Tags
Ajax
Asked by
rh
Top achievements
Rank 1
Answers by
rh
Top achievements
Rank 1
plamen
Top achievements
Rank 1
Share this question
or