asp.net开发控件"模块"的问题
小弟现在在自定义控件,学到了模块这里,但是遇到了点问题程序代码:
using System; using System.Collections.Generic; using System.Text; using System.Web; using System.Web.UI; using System.Web.UI.WebControls; using System.Drawing.Design; using System.Web.UI.Design; using namespace WebFormControl { [ToolboxData("<{0}:WebUserLoginControl3 runat=server UserLoginLableText=用户登陆 UserNameLableText=用户名 PassWordLableText=密码 SubmitButtonText=登陆></{0}:WebUserLoginControl3>")] public class WebUserLoginControl3 : WebUserLoginControl2 //1、继承WebUserLoginControl2类 { //2、创建模板属性 private ITemplate userloginlabletemplate; [TemplateContainer(typeof(UserInfoContainer))] public ITemplate UserLoginLableTemplate { get { return userloginlabletemplate; } set { userloginlabletemplate = value; } } private ITemplate usernamelabletemplate; [TemplateContainer(typeof(UserInfoContainer))] public ITemplate UserNameLableTemplate { get { return usernamelabletemplate; } set { usernamelabletemplate = value; } } private ITemplate passwordlabletemplate; [TemplateContainer(typeof(UserInfoContainer))] public ITemplate PassWordLableTemplate { get { return passwordlabletemplate; } set { passwordlabletemplate = value; } } private ITemplate submitbuttontemplate; [TemplateContainer(typeof(UserInfoContainer))] public ITemplate SubmitButtonTemplate { get { return submitbuttontemplate; } set { submitbuttontemplate = value; } } //3、重写WebUserLoginControl2类里的创建容器控件的子控件 protected override void CreateContainerChildContorl(UserInfoContainer container) { UserInfoContainer2 container2 = container as UserInfoContainer2; switch (container2.ContainerType) { case ContainerType.UserLoginLable: container2.LabelText = UserLoginLableText; if (userloginlabletemplate != null) userloginlabletemplate.InstantiateIn(container2); else base.CreateContainerChildContorl(container2); break; case ContainerType.UserNameLable: container2.LabelText = UserNameLableText; if (usernamelabletemplate != null) usernamelabletemplate.InstantiateIn(container2); else base.CreateContainerChildContorl(container2); break; case ContainerType.PassWordLable: container2.LabelText = PassWordLableText; if (passwordlabletemplate != null) passwordlabletemplate.InstantiateIn(container2); else base.CreateContainerChildContorl(container2); break; case ContainerType.SubmitButton: container2.LabelText = SubmitButtonText; if (submitbuttontemplate != null) submitbuttontemplate.InstantiateIn(container2); else base.CreateContainerChildContorl(container2); break; default: base.CreateContainerChildContorl(container2); break; } } //5、重写创建容器控件 protected override UserInfoContainer CreateContainer(ContainerType containertype) { return new UserInfoContainer2(containertype); } //6、重写Lable的Text属性 public override string UserLoginLableText { get { return ViewState["UserLoginLableText"] != null ? (string)ViewState["UserLoginLableText"] : "用户登陆"; } set { ViewState["UserLoginLableText"] = value; } } public override string UserNameLableText { get { return ViewState["UserNameLableText"] != null ? (string)ViewState["UserNameLableText"] : "用户名"; } set { ViewState["UserNameLableText"] = value; } } public override string PassWordLableText { get { return ViewState["PassWordLableText"] != null ? (string)ViewState["PassWordLableText"] : "密码"; } set { ViewState["PassWordLableText"] = value; } } public override string SubmitButtonText { get { return ViewState["SubmitButtonText"] != null ? (string)ViewState["SubmitButtonText"] : "登陆"; } set { ViewState["SubmitButtonText"] = value; } } public override void DataBind() { CreateChildControls(); base.DataBind(); } //4、继承原来的UserInfoContainer自定义容器控件 public class UserInfoContainer2 : UserInfoContainer { private string labelText; public UserInfoContainer2(ContainerType containerType) : base(containerType) { } public string LabelText { get { return labelText; } set { labelText = value; } } } } }页面上代码:
程序代码:
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %> <%@ Register Assembly="WebFormControl" Namespace="WebFormControl" TagPrefix="HchContorl" %> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www."> <html xmlns="http://www."> <head runat="server"> <title></title> </head> <body> <form id="form1" runat="server"> <div> <HchContorl:WebUserLoginControl3 ID="WebUserLoginControl1" runat="server" PassWordLableText="密码" SubmitButtonText="登陆" UserLoginLableText="用户登陆" UserNameLableText="用户名"> <UserNameLableTemplate>yhm</UserNameLableTemplate> </HchContorl:WebUserLoginControl3> </div> </form> </body> </html>但是会出现警告.希望高手帮忙下!