在外部JavaScript文件中使用服务器端方法

在外部JavaScript文件中使用服务器端方法

问题描述:

在C#ASPX项目。
我能达到在客户端的静态方法,在页面的开始部分进口我的命名空间,如下:

In a c# aspx project. I can reach a static method on client side with importing my namespace at the beginning part of the page, as follows.

<%@ Import Namespace="utl=portal.library.Utilities" %>

和比可以使用客户端上的相同asxp页面等。

And than in can use that on client side of the same asxp page like.

<script type="text/javascript">
var categoryPage;
categoryPage = '<%= utl.getcategoryName().ToString() %>';
</script>

我的问题是,我可以使用'&LT;%= utl.getcategoryName()的ToString()%>'?在外部JavaScript文件

My question is, can i use that '<%= utl.getcategoryName().ToString() %>' in an external javascript file ?

是否有可能类似的东西?

Is it possible something like that ?

<%@ Import Namespace="utl=portal.library.Utilities" %>
<script src="/scripts/trial.js" type="text/javascript"></script>

和在trial.js文件

and in the trial.js file

var categoryPage;
categoryPage = '<%= utl.getcategoryName().ToString() %>';

在此先感谢..

thanks in advance..

我不这么认为,因为外部.js文件不会被ASP.NET处理,因此不会有机会获得这些类型的变数。

I don't think so, because the external .JS file wouldn't be processed by ASP.NET and therefore wouldn't have access to those kinds of variables.