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

Minify RadScriptBlock Content

3 Answers 111 Views
Ajax
This is a migrated thread and some comments may be shown as answers.
ADe
Top achievements
Rank 1
ADe asked on 22 Feb 2010, 08:02 PM
I have a server side method that given a string of JScript as an input returns a compressed "minified" version.

I want to run some code after the page has loaded to find all RadCodeBlocks and RadScriptBlocks and minify their content before the page is finally rendered in the browser.

I can do this for some RadScriptBlocks but not all of them.

Some of them simply appear to have no sub controls at all and so I can't get what they currently contain in order to minify them.

I call something similar to the following in every page's Page_PreRender,

 
        public static void MinifyAllPageJScript(ControlCollection PageControls)  
        {  
            foreach (Control pageControl in PageControls)  
            {  
                if ((pageControl as RadScriptBlock) != null ||  
                    (pageControl as RadCodeBlock) != null)  
                {  
                    foreach (Control script in pageControl.Controls)  
                    {  
                        if ((script as LiteralControl) != null)  
                        {  
                            (script as LiteralControl).Text = Common.CompressJS((script as LiteralControl).Text);  
                        }  
                    }  
                }  
                MinifyAllPageJScript(pageControl.Controls);  
            }  
        } 

Like I say, it successfully finds all the RadScriptBlocks and RadCodeBlocks on every page but some of them have Controls.Count = 0 and so I can't get at their content to correct it. Have tried calling my MinifyAllPageJScript from various event methods but with no luck.

Little help?

Regards
ADe

3 Answers, 1 is accepted

Sort by
0
robertw102
Top achievements
Rank 1
answered on 23 Feb 2010, 02:28 PM
The reason the controls collection contains no controls is because the script tags inside the RadScriptBlock/RadCodeBlock are not server controls, you would need to set the script tags to runat="server" and then they should show up in the controls collection.

I hope that helps.
0
ADe
Top achievements
Rank 1
answered on 23 Feb 2010, 03:02 PM
Doh! Of course. Thanks.

Problem is, if I do that then it complains about my use of the $find command saying that $ is an invalid character.
0
robertw102
Top achievements
Rank 1
answered on 23 Feb 2010, 07:18 PM
I believe it does that because when you set the script tag to runat="server", it's expecting .NET code to be inside of it. It pretty much turns it into a .NET code block.

So I don't know how you would resolve something like that.
Tags
Ajax
Asked by
ADe
Top achievements
Rank 1
Answers by
robertw102
Top achievements
Rank 1
ADe
Top achievements
Rank 1
Share this question
or