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

Script in nested user control (ascx) not available

10 Answers 265 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Polaris431
Top achievements
Rank 1
Polaris431 asked on 01 Sep 2009, 03:24 PM
When a user edits a row in my RadGrid, a popup form is used to edit it. The WebUserControl that is used will vary depending on what is being edited. I set the WebUserControl as follows:

e.Item.OwnerTableView.EditFormSettings.UserControlName = "PropertyListsNumber.ascx"

In PropertyListsNumber.ascx I have another user control. This nested control is a RadComboBox. The combobox is populated with checkboxes and javascript is used to concatenate the checked selections, as shown in one of the Telerik demos. The combobox does get populated but when you go to check off an item in the dropdown, a run-time error occurs indicating that the object could not be found. I have verified that my Javascript code is correct.

It isn't even possible to set a breakpoint or open any script in VS to set one. Even using "debugger;" will not work. After playing around with the code, I moved the javascript outside of the nested control and put it into a normal javascript file and had the script registered from the page hosting the control that was hosting the nested control. I was able to get a breakpoint to work although this really didn't help to solve my problem. What it did tell me is that if the script is not registered, it cannot get executed. I was under the impression that any user controls, no matter how nested they are, all get merged and the scripts get executed. That does not seem to be the case. If you look at the code I am showing above, the user control gets set at run-time, so it appears that ASP.NET is not even aware of the script since it could not have gotten registered at runtime, which might explain why it isn't getting executed.

I also tried using RegisterScriptBlock and RegisterCodeBlock inside the nested control but that did not help either.

So how can I get the script in the nested control to get executed? Or maybe even more to the point, how can I get it registered?

Thanks
Johann

10 Answers, 1 is accepted

Sort by
0
Vlad
Telerik team
answered on 02 Sep 2009, 06:51 AM
Hi Johann,

You can wrap your JavaScript with RadScriptBlock - please check this article for more info:
http://www.telerik.com/help/aspnet-ajax/ajxradscriptblockradcodeblock.html

All the best,
Vlad
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
0
Polaris431
Top achievements
Rank 1
answered on 02 Sep 2009, 07:45 AM
I made a mistake in my post. I wrote "RegisterScriptBlock" and "RegisterCodeBlock". I really meant "RadScriptBlock" and "RadCodeBlock" and neither of those worked.
0
Vlad
Telerik team
answered on 02 Sep 2009, 07:52 AM
Hi,

Can you show us an example where RadScriptBlock does not work?

Kind regards,
Vlad
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
0
Apostol Apostolov
Top achievements
Rank 1
answered on 16 Jul 2010, 04:39 PM
Hey Telerik, 

I have the exact same problem. Is there a solution?

Thanks,
Apostol Apostolov
0
Ying
Top achievements
Rank 1
answered on 26 Jul 2010, 11:02 PM
I have the exact same problem. Wrapped script within a RadScriptBlock and it did not register.
0
Maria Ilieva
Telerik team
answered on 29 Jul 2010, 03:14 PM
Hello,

 Could you please open a formal support ticket and send us small runnable application which demonstrates the issue? We will test it locally and advise you further.

Greetings,
Maria Ilieva
the Telerik team

Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
0
Antony
Top achievements
Rank 1
answered on 03 Aug 2010, 10:59 AM
Has this been resolved as I have the same problem, script in my WebUsercontrol used for editing grid rows will not execute.

I have tracked the issue further:

If my Grid is within an ASP UpdatePanel then the Ajax pageLoad function is not executed in my WebUsercontrol when attempting to edit a row.
If I change the ASP UpdatePanel to be a RadAjaxPanel then the Ajax pageLoad function is executed in my WebUserControl as expected providing that the Javascript in the WebUserControl is encased by the RadScriptBlock.

I did notice however another strange issue, I have a hierachical grid, with 2 levels, both levels use different WebUserControls for editing. I placed an alert in the 2nd level edit usercontrol, this was displayed when I attempted to edit the 2nd level row as expected, but it was also displayed when I attempted to edit the parent row ie. 1st level which uses a completely different Webusercontrol. However when I added a RadScriptBlock with an alert into the 1st Level webusercontrol as well then the correct Alerts were displayed when editing the various levels.

I think this needs Telerik to investigate further and bug fix.

Thanks
Antony
0
Veli
Telerik team
answered on 06 Aug 2010, 09:32 AM
Hi Guys,

Let me clarify one important point: RadScriptBlock does not work with the UpdatePanel control. Only Telerik RadAjax controls are supported with the RadScriptBlock.

@Antony:
We cannot reproduce the issue you are describing with edit forms on 2 different hierarchy levels in RadGrid. Scripts all appear to be properly registered. Can you share any sample code and exact instructions on how to reproduce this?  Also note that if you are registering for AJAX client events such as with Sys.Application.add_load(), note that the event handlers persist through AJAX postbacks. Chances are you are getting AJAX events firing with previously added handlers even though the user controls that registered the scripts are removed from the page.

I hope it is clearer now.

Regards,
Veli
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
0
Lucania
Top achievements
Rank 1
answered on 13 Jun 2012, 06:44 AM
I have a complicated scenario that's difficult to duplicate without the whole app, My page has a user control on it, that loads other user controls dynamically. They are all always loaded, but the appropriate one(s) are made visible depending on various conditions. One of the sub-controls has a RadScriptBlock with some javascript. One of the js functions is set as the OnClientClick of a LinkButton on the sub-control. The first time the button is clicked, it gets an error "function not defined", so the button generates a partial postback. After that, the button works fine, all the javascript is available.

I have taken all the static code out of the RadScriptBlock and included it in a external js file using ScriptManager.RegisterClientScriptInclude() and it works fine, with a bit of tweaking I can move the code that relies on server calls to that file too, but I'm intrigued why the script block doesn't seem to be registered on the initial load?

I've verified that the sub-control is visible in the page PreRender event, I would have thought as long as that's the case it should be registered correctly? Or are RadScriptBlocks registered earlier than that?

Thanks for any insight,

ROSCO
0
Maria Ilieva
Telerik team
answered on 18 Jun 2012, 09:00 AM
Hello Ross,

Actually the ScriptBlocks should be properly registered in pageLoad and I'm not completely sure what exactly is causing the issue in your case. Could you please try to timeout the function execution and verify if the error still persists. Also please ensure that on the server the scripts are loaded through the Page as it should be with ajax calls. See the topic below:
http://www.telerik.com/help/aspnet-ajax/ajax-execute-custom-javascript.html

Kind regards,
Maria Ilieva
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
Grid
Asked by
Polaris431
Top achievements
Rank 1
Answers by
Vlad
Telerik team
Polaris431
Top achievements
Rank 1
Apostol Apostolov
Top achievements
Rank 1
Ying
Top achievements
Rank 1
Maria Ilieva
Telerik team
Antony
Top achievements
Rank 1
Veli
Telerik team
Lucania
Top achievements
Rank 1
Share this question
or