我能否将一个变量传递给链接的.js文件?我尝试过这个方法:
<sf:JsFileLink ID="JQueryLoader" runat="server" ScriptType="Custom" FileName="~/Files/Scripts/rotatorLoader.js?timeout=1000" />
然而,Firebug告诉我timeout未定义。以下是该.js文件的代码:
$(document).ready(function() {
$("#rotator > ul").tabs({ fx: { opacity: "toggle"} }).tabs("rotate", timeout, true);
});
我使用<sf:JsFileLink ... />
标签是因为我所在的网站采用了Sitefinity,这个标签允许我加载外部的.js文件。
更新:
我通过创建一个模拟JavaScript页面的aspx页面来“欺骗”包含操作:
<%@ Page Language="C#" %>
<%
Response.ContentType = "text/javascript";
Response.Clear();
string timeout;
try
{
timeout = Session["timeout"].ToString();
}
catch
{
timeout = "4000";
}
%>
$(document).ready(function() {
$("#rotator > ul").tabs({ fx: { opacity: "toggle"} }).tabs("rotate", <%=timeout %>, true);
});
并且在用户控制页面上:
[DefaultProperty("BannerTimeout")]
public partial class Custom_UserControls_TabbedRotator : System.Web.UI.UserControl
{
[Category("Configuration")]
[Description("Sets the rotation timeout, in seconds.")]
[DisplayName("Banner Timeout")]
public int BannerTimeout { get; set; }
protected void Page_Load(object sender, EventArgs e)
{
Session.Add("timeout", (BannerTimeout*1000));
}
}
这达到了我想要的结果,也许这种方法可以帮助其他人。