| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 508 人关注过本帖
标题:asp.net开发控件"模块"的问题
只看楼主 加入收藏
等待冰柠檬
Rank: 2
来 自:浙江温州
等 级:论坛游民
帖 子:208
专家分:70
注 册:2008-6-25
结帖率:66.67%
收藏
 问题点数:0 回复次数:0 
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>
但是会出现警告.希望高手帮忙下!
图片附件: 游客没有浏览图片的权限,请 登录注册



搜索更多相关主题的帖子: 开发 
2011-08-22 15:49
快速回复:asp.net开发控件"模块"的问题
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.055540 second(s), 8 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved