BasePage = (CurrentPage \ 10) * 10 是什么意思。急?

cnynkmzm 2003-09-27 03:49:27
谢谢
...全文
38 1 打赏 收藏 转发到动态 举报
写回复
用AI写文章
1 条回复
切换为时间正序
请发表友善的回复…
发表回复
cnynkmzm 2003-09-27
  • 打赏
  • 举报
回复
谁能告诉我 \ 是什么运算符号
场景:在自定义控件、用户控件、页面、后台代码都会有引用JS的可能,这就会出现混乱或者重复引用的可能。 一个自定义控件,用于在ASPX页面中注册JS: public class Script : Control {   #region 属性   private string m_Src;   ///    /// 脚本文件路径   ///    public string Src   {     get { return m_Src; }     set { m_Src = value; }   }   #endregion   ///    /// 在控件Init的时候将JS路径添加到HttpContext.Current.Items["IncludedJavaScript"]中。   ///    ///    protected override void OnInit(EventArgs e)   {     base.OnInit(e);     if (!string.IsNullOrEmpty(Src))     {       string src = ResolveUrl(Src);       List includedJs = HttpContext.Current.Items["IncludedJavaScript"] as List;       if (null == includedJs)       {         includedJs = new List();         HttpContext.Current.Items["IncludedJavaScript"] = includedJs;       }       if (!includedJs.Contains(src))       {         includedJs.Add(src);       }     }   } } 一个静态类,用于管理JS和在后台代码(cs文件)中注册JS: ///  /// Javascript管理器 ///  public static class JavaScriptManager {   ///    /// 包含JS引用。   ///    ///    public static void Include(params string[] filePaths)   {     HttpContext context = HttpContext.Current;     if (null == context)     {       throw new Exception("HttpContext为空。");     }     System.Web.UI.Page p = context.CurrentHandler as System.Web.UI.Page;     if (null == p)     {       throw new Exception("HttpContext.CurrentHandler不是Page。");     }     IList jss = GetIncludedJavaScript();     string resolveUrl;     foreach (string filePath in filePaths)     {       resolveUrl=p.ResolveUrl(filePath);       if (!jss.Contains(resolveUrl))       {         jss.Add(p.ResolveUrl(resolveUrl));       }     }   }   ///    /// 获取已经包含的JS列表   ///    ///    public static IList GetIncludedJavaScript()   {     HttpContext context = HttpContext.Current;     if (null == context)     {       throw new Exception("HttpContext为空。");     }     IList jss = HttpContext.Current.Items["IncludedJavaScript"] as IList;     if (null == jss)     {       jss = new List();       HttpContext.Current.Items["IncludedJavaScript"] = jss;     }     return jss;   } } 然后写一个基类页面,所有的页面都要继承自这个基类页: public class BasePage : System.Web.UI.Page {   public BasePage() { }   #region 注册/管理JS引用   ///    /// 将引用的JS添加到Page.Head中。   ///    private void InitJS()   {     IList includedJs = JavaScriptManager.JavaScriptManager.GetIncludedJavaScript();     foreach (string jsFilePath in includedJs)     {       var script = new HtmlGenericControl("script");       script.Attributes["type"] = "text/javascript";       script.Attributes["src"] = jsFilePath;       Page.Header.Controls.Add(script);     }   }   ///    /// 在呈现之前注册JS   ///    ///    protected override void OnPreRender(EventArgs e)   {     base.OnPreRender(e);     InitJS();   }   #endregion } 上面是在OnPreRender中将JS注册到Page.Head中的,所以如果在自定义控件中注册JS引用,请在OnPreRender之前引用。 在ASPX页面中注册JS:                                  在CS页面中注册JS: public partial class _Default : BasePage {   protected void Page_Load(object sender, EventArgs e)   {     JavaScriptManager.JavaScriptManager.Include("~/JS/cs.js",       "~/JS/cs.js",       "~/JS/cs.js2",       "~/JS/cs.js");   } }

28,406

社区成员

发帖
与我相关
我的任务
社区描述
ASP即Active Server Pages,是Microsoft公司开发的服务器端脚本环境。
社区管理员
  • ASP
  • 无·法
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧