我在AssemblyInfo.cs里设置了
[assembly: WebResource("MyDiaryControl.css_js.md_001.md_001.css", "text/css")]
[assembly: WebResource("MyDiaryControl.css_js.md_001.md_001.js", "text/js")]
[assembly: WebResource("MyDiaryControl.css_js.md_001.md_001.gif", "image/gif")]

this.Page.ClientScript.GetWebResourceUrl(this.GetType(), "MyDiaryControl.css_js.md_001.md_001.gif")
能正确调出图片,但我想在拖入该控件的时候自动在页面<title>下加入
<link rel="stylesheet" type="text/css" href="md_001.css" />
<script src="jquery-1.2.6.min.js"></script>
等CSS和JS的嵌入,而且判断如果存在这样的嵌入(可能有两个控件同用一个JS情况)就省去,应该怎么实现这个,谢谢!!!!

解决方案 »

  1.   

    那你就用JS脚本来判断呗,具体就是你调用那个JS里面的一个脚本,只要不出错,说明就已经引用.否则就用JS代码引用你所需要的JS文件
      

  2.   

            // 注册css和js
            protected override void OnPreRender(EventArgs e)
            {
                HtmlLink hl = new HtmlLink();
                hl.Href = this.GetWebResourceUrl("DatePicker.Calendar.css");
                hl.Attributes.Add("rel", "stylesheet");
                hl.Attributes.Add("type", "text/css");
                this.Page.Header.Controls.Add(hl);            this.Page.ClientScript.RegisterClientScriptInclude("CalendarFile",
                    this.GetWebResourceUrl("DatePicker.Calendar.js"));            StringBuilder sb = new StringBuilder(1000);
                sb.Append("<script type=\"text/javascript\">");
                sb.AppendFormat("function doCalendar{0}(objId, objIdHidden)", this.ClientID);
                sb.Append("{var calendar = new MatchCalendarClass();");
                sb.AppendFormat("calendar.Style = {0};", this.GetCssStyle(this.CssStyle));
                sb.AppendFormat("calendar.StartDate = new Date({0},{1},{2});", 
                    this.MinDate.Year, this.MinDate.Month - 1, this.MinDate.Day);
                sb.AppendFormat("calendar.EndDate = new Date({0},{1},{2});", 
                    this.MaxDate.Year, this.MaxDate.Month - 1, this.MaxDate.Day);
                sb.AppendFormat("calendar.Date = new Date({0},{1},{2});", 
                    this.CurrentDate.Year, this.CurrentDate.Month - 1, this.CurrentDate.Day - 1);
                sb.Append("calendar.Object = document.getElementById(objId);");
                sb.Append("calendar.ObjectHidden = document.getElementById(objIdHidden);");
                sb.AppendFormat("calendar.IsClick = {0};", this.GetBool(this.ClickHidden));
                sb.AppendFormat("calendar.IsOverHidden = {0};", this.GetBool(this.OverHidden));
                sb.AppendFormat("calendar.IsClearHidden = {0};", this.GetBool(this.ClearHidden));
                sb.AppendFormat("calendar.Type = \"{0}\";", this.GetTypeOut(this.TypeOut));
                sb.AppendFormat("calendar.Attach = {0};", this.GetBool(this.Attach));
                sb.AppendFormat("calendar.Language = \"{0}\";", this.GetLanguageCode(this.Language));
                sb.AppendFormat("calendar.Position = {0};", this.GetBool(this.Position));
                sb.AppendFormat("calendar.FormatOut = \"{0}\";", this.FormatString);
                sb.Append("calendar.Calendar();}");
                sb.Append("</script>");
                this.Page.ClientScript.RegisterStartupScript(this.GetType(), "CalendarJS" + this.ClientID, sb.ToString());            base.OnPreRender(e);
            }