日期:2014-05-19  浏览次数:20524 次

~~~~~~~~救助关于服务器控件的问题!!!!

第一天上班,经理考我,要我做这样一个控件:
用asp.net做一个服务器控件A,控件里包含三个子控件:一个普通TextBox框,一个下拉框控件,一个时间控件。要求在A控件里添加一个属性,属性值可以通过下拉选择(下拉里面的值为:TextBox,DropDownTextBox,DateTimeTextBox),
当选择TextBox时,控件A在界面上显示为一个普通TextBox框,
当选择DropDownTextBox时,控件A在界面上显示为一个下拉框控件,
当选择DateTimeTextBox时,控件A在界面上显示为一个时间控件。

        向各位高手救助!

------解决方案--------------------
要求在A控件里添加一个属性,属性值可以通过下拉选择(下拉里面的值为:TextBox,DropDownTextBox,DateTimeTextBox),
这是什么意思?
------解决方案--------------------
我是2003的 我做了一个可以选择出Button TextBox Label的你看看 应该差不多的
ASCX:
<%@ Control Language= "c# " AutoEventWireup= "false " Codebehind= "WebUserControl1.ascx.cs " Inherits= "www1.WebUserControl1 " TargetSchema= "http://schemas.microsoft.com/intellisense/ie5 "%>
<asp:DropDownList id= "DropDownList1 " runat= "server ">
<asp:ListItem Value= "TextBox "> TextBox </asp:ListItem>
<asp:ListItem Value= "Button "> Button </asp:ListItem>
<asp:ListItem Value= "Label "> Label </asp:ListItem>
</asp:DropDownList>


ASCX后台:
namespace www1
{
using System;
using System.Data;
using System.Drawing;
using System.Web;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;

/// <summary>
/// WebUserControl1 的摘要说明。
/// </summary>
public class WebUserControl1 : System.Web.UI.UserControl
{
protected System.Web.UI.WebControls.DropDownList DropDownList1;

public string GetType
{
get
{
return this.DropDownList1.SelectedValue;
}
}


private void Page_Load(object sender, System.EventArgs e)
{
// 在此处放置用户代码以初始化页面
}

#region Web 窗体设计器生成的代码
override protected void OnInit(EventArgs e)
{
//
// CODEGEN: 该调用是 ASP.NET Web 窗体设计器所必需的。
//
InitializeComponent();
base.OnInit(e);
}

/// <summary>
/// 设计器支持所需的方法 - 不要使用代码编辑器
/// 修改此方法的内容。
/// </summary>
private void InitializeComponent()
{
this.Load += new System.EventHandler(this.Page_Load);

}
#endregion
}
}


ASPX前台:

<%@ Page language= "c# " Codebehind= "WebForm1.aspx.cs " AutoEventWireup= "false " Inherits= "www1.WebForm1 " %>
<%@ Register TagPrefix= "uc1 " TagName= "WebUserControl1 " Src= "WebUserControl1.ascx " %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN " >
<HTML>
<HEAD>
<title> WebForm1 </title>
<meta name= "GENERATOR " Content= "Microsoft Visual Studio .NET 7.1 ">
<meta name= "CODE_LANGUAGE " Content= "C# ">
<meta name= "vs_defaultClientScript " content= "JavaScript ">
<meta name= "vs_targetSchema " content= "http://schemas.microsoft.com/intellisense/ie5 ">
</HEAD>
<body MS_POSITIONING= "GridLayout ">
<form id= "Form1 " method= "post " runat= "server ">
<FONT face= "宋体 ">
<uc1:WebUserControl1 id= "WebUserControl11 " runat= "server "> </uc1:WebUserControl1>