ASP.NET2.0自定义控件开发(3) ----给控件添加下拉列表属性

3.给控件添加下拉列表属性

 


using  System;
using  System.Web.UI;
using  System.Web.UI.WebControls;
using  System.ComponentModel;

namespace  CustomControls
{
    
/// 
    
/// Summary description for LabelTextBox
    
/// 

    public class LabelTextBox : Control
    
{
        
private string _labelText="LabelText";
        
private string _textBoxText = "";

        [Browsable(
true),
         Description(
"获取和设置Label文本"),
         DefaultValue(
"LabelText"),
         Category(
"Appearance")
        ]
        
public virtual string Title
        
{
            
get return _labelText; }
            
set { _labelText = value; }
        }


        [Browsable(
true),
         Description(
"获取和设置TextBox文本"),
         DefaultValue(
""),
         Category(
"Appearance")
        ]
        
public virtual string Text
        
{
            
get return _textBoxText; }
            
set { _textBoxText = value; }
        }


        [Browsable(
true),
         Description(
"获取和设置TextBox的显示方式"),
         DefaultValue(
""),
         Category(
"Appearance")
        ]
        
public virtual TextBoxMode TextMode
        
{
            
get
            
{
                
object _textMode = ViewState["TextMode"];
                
if (_textMode == null)
                    
return TextBoxMode.SingleLine;
                
else
                    
return (TextBoxMode)_textMode;
            }

            
set
            
{
                ViewState[
"TextMode"= value;
            }

        }


        
protected override void Render(HtmlTextWriter writer)
        
{
            Page.VerifyRenderingInServerForm(
this);

            
if (TextMode == TextBoxMode.SingleLine)
            
{
                writer.Write(
"");
                writer.Write(
"");
                writer.Write(
"" + _labelText + "
");
                writer.Write(
"");
                writer.Write(
"");
                writer.Write(
"");
            }

            
else if (TextMode == TextBoxMode.MultiLine)
            
{
                writer.Write(
"");
                writer.Write(
"");
                writer.Write(
"" + _labelText + "
");
                writer.Write(
"");
                writer.Write(
"");
                writer.Write(
"");
            }

            
else if (TextMode == TextBoxMode.Password)
            
{
                writer.Write(
"");
                writer.Write(
"");
                writer.Write(
"" + _labelText + "
");
                writer.Write(
"");
                writer.Write(
"");
                writer.Write(
"");
            }


            
base.Render(writer);
        }

    }

}

 

你可能感兴趣的:(asp.net,textbox,string,object,system,class)