是否可以将变量传递给链接的 .js 文件?我试过这个:
<sf:JsFileLink ID="JQueryLoader" runat="server" ScriptType="Custom" FileName="~/Files/Scripts/rotatorLoader.js?timeout=1000" />
但是萤火虫告诉我没有定义超时。这是该 .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));
}
}
这实现了我想要的,也许这种方法可以帮助别人。