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

[Solved] RadCodeBlock and referenced js files

3 Answers 316 Views
Ajax
This is a migrated thread and some comments may be shown as answers.
Ross
Top achievements
Rank 1
Ross asked on 09 Apr 2009, 10:08 AM
I am already using the RadCodeBlock to allow server code to be embedded in the javascript markup, i.e.

<telerik:RadCodeBlock ID="RadCodeBlock1" runat="server">
   
<script language="javascript" type="text/javascript">
        
function AjaxReq(args) {
           $find("
<%= RadAjaxPanel1.ClientID %>").ajaxRequestWithTarget("<%= Button1.UniqueID %>", '');
         }
   
</script>
</
telerik:RadCodeBlock>

Is it possible to do the same thing with externally referenced javascript files?  i.e.

<telerik:RadCodeBlock ID="RadCodeBlock1" runat="server">
   
<script language="javascript" type="text/javascript" src="myscript.js"></script>
</
telerik:RadCodeBlock>
--------------------------------------------------------------------------------------------------------------------------------------------
MyScript.js

        function AjaxReq(args) {
           $find("
<%= RadAjaxPanel1.ClientID %>").ajaxRequestWithTarget("<%= Button1.UniqueID %>", '');
         }
--------------------------------------------------------------------------------------------------------------------------------------------


I don't want to put all my javascript in the aspx page itself, to allow re-use etc.

Thanks.

3 Answers, 1 is accepted

Sort by
0
Dimo
Telerik team
answered on 09 Apr 2009, 10:22 AM
Hello Ross,

You cannot have code blocks ( <%= .... %> ) in external JS files, because they will not be evaluated. If you want to reuse your Javascript, you can assign controls' ClientIDs to global variables in the ASPX page and use these global variables in the JS file.


Regards,
Dimo
the Telerik team

Check out Telerik Trainer , the state of the art learning tool for Telerik products.
0
Ross
Top achievements
Rank 1
answered on 09 Apr 2009, 10:25 AM
Will they be evaluated if they are embedded resources and referenced using the RadScriptManager?
0
Dimo
Telerik team
answered on 09 Apr 2009, 10:57 AM
Hi Ross,

Code blocks work only in web pages, user controls, master pages, etc.. They do not work in Javascript and CSS files, no matter how you register them.

There is one exception - you can rename myscripts.js to myscript.js.aspx and add a directive at the top:

<%@ Page Language="C#" ContentType="text/javascript" %>

In this case code blocks will be evaluated, but the context will be different, so you will not be able to access controls from the "parent" page in a straightforward way.

All the best,
Dimo
the Telerik team

Check out Telerik Trainer , the state of the art learning tool for Telerik products.
Tags
Ajax
Asked by
Ross
Top achievements
Rank 1
Answers by
Dimo
Telerik team
Ross
Top achievements
Rank 1
Share this question
or