问题描述
会提示元素“DatePicker”不是已知元素,原因可能是网站中存在编译错误下面是代码:<%@ControlLanguage="c#"ClassName="DateandTimePicker"%><%@RegisterTagPrefix="Club"Namespace="ClubSite"%><divclass="controlblock"><table><tr><td>Date:</td><td><Club:DatePickerid="dp1"runat="server"/><!--日期下拉列表--></td><td>Time:</td><td><Club:TimePickerID="tp1"runat="server"/><!--时间下拉列表--></td></tr></table></div><scriptrunat="server">Datepicker的源代码:usingSystem.Web;usingSystem.Web.UI;usingSystem.Web.UI.WebControls;usingSystem.Text;namespaceClubSite{publicstaticclasscommonScript{publicstaticvoidWritePopupRoutines(System.Web.UI.PagePage){StringBuildersb=newStringBuilder();sb=newStringBuilder();sb.AppendLine("var__popup_panel;");sb.AppendLine("function__popup_clear(){");sb.AppendLine("if(__popup_panel!=null)");sb.AppendLine("{");sb.AppendLine("document.getElementById(__popup_panel).style.display='none';");sb.AppendLine("__popup_panel=null;");sb.AppendLine("}");sb.AppendLine("}");sb.AppendLine("function__popup_losefocus(panel)");sb.AppendLine("{");sb.AppendLine("if(!panel.contains(document.activeElement))");sb.AppendLine("{");sb.AppendLine("panel.style.display='none';");sb.AppendLine("}");sb.AppendLine("}");Page.ClientScript.RegisterClientScriptBlock(Page.GetType(),"PopupRoutines",sb.ToString(),true);}}publicclassDatePicker:WebControl,INamingContainer{privateCalendar_innerCal;privateTextBox_innerTbx;privatestringerrorText=null;privatebool_panelvisible=false;publicDatePicker():base(HtmlTextWriterTag.Div){}publicSystem.DateTimeSelectedDate{get{EnsureChildControls();System.DateTimed=System.DateTime.Now;try{d=System.DateTime.Parse(_innerTbx.Text);errorText=null;_innerCal.SelectedDate=d;}catch{errorText="Dateneedstobespecifiedasmm/dd/yyyy";}returnd;}set{EnsureChildControls();_innerCal.SelectedDate=value;_innerTbx.Text=value.ToShortDateString();}}protectedoverridevoidCreateChildControls(){base.CreateChildControls();_innerTbx=newTextBox();this.Controls.Add(_innerTbx);_innerCal=newCalendar();_innerCal.SelectionChanged+=newSystem.EventHandler(_innerCal_SelectionChanged);_innerCal.VisibleMonthChanged+=newMonthChangedEventHandler(_innerCal_MonthChanged);Controls.Add(_innerCal);}protectedoverrideSystem.Web.UI.HtmlTextWriterTagTagKey{get{returnHtmlTextWriterTag.Div;}}protectedoverridevoidAddAttributesToRender(System.Web.UI.HtmlTextWriterwriter){if(this.Width.IsEmpty){this.Width=newUnit(150);}base.AddAttributesToRender(writer);}protectedoverridevoidRenderContents(System.Web.UI.HtmlTextWriterwriter){_innerTbx.Attributes.Add("Align","AbsMiddle");_innerTbx.Width=newUnit(100);_innerTbx.RenderControl(writer);stringinnerid=this.UniqueID+"_inner";writer.AddAttribute("Align","AbsMiddle");writer.AddAttribute("src","images/dropdownbtn.gif");writer.AddAttribute("onClick","__datepicker_showpopup('"+innerid+"')");writer.RenderBeginTag(HtmlTextWriterTag.Img);writer.RenderEndTag();if(errorText!=null){writer.AddStyleAttribute("color","red");writer.AddStyleAttribute("display","block");writer.RenderBeginTag(HtmlTextWriterTag.Span);writer.Write(errorText);writer.RenderEndTag();}writer.AddStyleAttribute("position","relative");writer.RenderBeginTag(HtmlTextWriterTag.Div);writer.AddStyleAttribute("position","absolute");writer.AddStyleAttribute("left","0px");writer.AddStyleAttribute("top","0px");writer.AddStyleAttribute("z-index","100");stringpanelvisible=_panelvisible?"block":panelvisible="none";writer.AddStyleAttribute("display",panelvisible);writer.AddStyleAttribute("background-color","white");writer.AddAttribute("id",innerid);writer.AddAttribute("onfocusout","__popup_losefocus(this)");writer.RenderBeginTag(HtmlTextWriterTag.Div);_innerCal.RenderControl(writer);writer.RenderEndTag();writer.RenderEndTag();}protectedoverridevoidOnPreRender(System.EventArgse){base.OnPreRender(e);commonScript.WritePopupRoutines(Page);StringBuildersb=newStringBuilder();if(_panelvisible){sb.AppendLine("__popup_panel='"+this.UniqueID+"_inner';");}sb.AppendLine("function__datepicker_showpopup(name)");sb.AppendLine("{");sb.AppendLine("if(__popup_panel!=null)");sb.AppendLine("{");sb.AppendLine("document.getElementById(__popup_panel).style.display='none';");sb.AppendLine("}");sb.AppendLine("__popup_panel=name;");sb.AppendLine("varpanel=document.getElementById(__popup_panel);");sb.AppendLine("panel.style.display='block';");sb.AppendLine("varlinks=panel.getElementsByTagName('A');");sb.AppendLine("links[0].focus();");sb.AppendLine("window.event.cancelBubble=true;");sb.AppendLine("}");Page.ClientScript.RegisterClientScriptBlock(this.GetType(),"popup",sb.ToString(),true);Page.MaintainScrollPositionOnPostBack=true;}privatevoid_innerCal_SelectionChanged(objectsender,System.EventArgse){EnsureChildControls();_innerTbx.Text=_innerCal.SelectedDate.ToShortDateString();}privatevoid_innerCal_MonthChanged(objectsender,MonthChangedEventArgse){_panelvisible=true;}}}
解决方案
解决方案二:
添加引用后重新生成一下