首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 网站开发 > asp.net >

自定义textbox控件如何取得到输入的value值和保存返回

2012-01-19 
自定义textbox控件怎么取得到输入的value值和保存返回!下面是我定义的一个textbox控件,怎么每次在onblur后

自定义textbox控件怎么取得到输入的value值和保存返回!
下面是我定义的一个textbox控件,怎么每次在onblur后输入的都没有了!我怎么去保存输入的值或者取得!

回答者不要说继承textbox类!
using   System;
using   System.Collections.Generic;
using   System.Text;
using   System.ComponentModel;
using   System.ComponentModel.Design;
using   System.Web;
using   System.Web.UI;
using   System.Web.UI.WebControls;
using   System.Security;
using   System.Security.Permissions;
using   System.Drawing;

namespace   ValidateTextInput
{

        [DefaultProperty( "Input ")]
        [ToolboxData( " <{0}:ValidateInput   runat=server> </{0}:ValidateInput> ")]
        public   class   ValidateInput:   Control,IPostBackEventHandler
        {
                [Bindable(true),
                  Category( "Appearance "),
                  DefaultValue( " "),
                Description( "文本值 "),
                  Localizable(true),
                PersistenceMode(PersistenceMode.InnerDefaultProperty)
                ]
                public   virtual   string   Text
                {
                        get
                        {
                              string   s   =   (string)ViewState[ "Text "];
                                return   (s   ==   null)   ?   String.Empty   :   s;
                        }
                    set
                        {
                                ViewState[ "Text "]   =   value;
                      }
                }
           
                [Bindable(true),
                Category( "Appearance "),
                DefaultValue( " "),
              Description( "文本值 "),
                Localizable(true),
              PersistenceMode(PersistenceMode.InnerDefaultProperty)
                ]
                public   string   Value
                {


                        get
                        {
                                string   s   =   (string)ViewState[ "Value "];
                                return   (s   ==   null)   ?   String.Empty   :   s;
                        }
                        set
                        {
                                ViewState[ "Value "]   =   value;
                        }
                }
                [Bindable(true),   Category( "Appearance "),   DefaultValue( " "),   Description( "宽度 ")]
                public   Unit   Width
                {
                        get
                        {
                                object   o   =   ViewState[ "Width "];
                                return   (o   ==   null)   ?   Unit.Empty   :   (Unit)o;
                        }
                        set
                        {
                                if   (value.Value   <   0)
                                        throw   new   ArgumentOutOfRangeException( "value ");
                                ViewState[ "Width "]   =   value;
                        }
 
                }

                [Bindable(true),Category( "Appearance "),DefaultValue( " "),Description( "高度 ")]
                public   Unit   Height
                {
                        get
                        {
                                object   o   =   ViewState[ "Height "];


                                return   (o   ==   null)   ?   Unit.Empty   :   (Unit)o;
                        }
                        set
                        {
                                if   (value.Value   <   0)
                                        throw   new   ArgumentOutOfRangeException( "value ");
                                ViewState[ "Height "]   =   value;
                        }
                }
                [Bindable(true),   Category( "Appearance "),   DefaultValue(typeof(Color), " "),   Description( "控件背景颜色 "),TypeConverter(typeof(WebControl))]
                public   Color   BackColor
                {
                        get
                        {
                                object   o   =   ViewState[ "BackColor "];
                                return   (o   ==   null)   ?   Color.Empty   :   (Color)o;
                        }
                        set
                        {
                                ViewState[ "BackColor "]   =   value;
                        }
                }
                [Bindable(true),   Category( "Appearance "),   DefaultValue(typeof(Color),   " "),   Description( "控件边框颜色 "),   TypeConverter(typeof(WebControl))]
                public   Color   BorderColor
                {
                        get
                        {
                                object   o   =   ViewState[ "BorderColor "];
                                return   (o   ==   null)   ?   Color.Empty   :   (Color)o;


                        }
                        set
                        {
                                ViewState[ "BorderColor "]   =   value;
                        }
                }

           
                protected   override   void   Render(HtmlTextWriter   writer)
                {

                        writer.AddAttribute(HtmlTextWriterAttribute.Type,
                            "Text ");
                        writer.AddAttribute(HtmlTextWriterAttribute.Name,
                                this.UniqueID);
                        writer.AddAttribute(HtmlTextWriterAttribute.Id,
                                this.ID);
                        writer.AddAttribute(HtmlTextWriterAttribute.Value,   this.Value);
                        writer.AddAttribute( "onblur ",   Page.GetPostBackEventReference(this));
                        writer.RenderBeginTag(HtmlTextWriterTag.Input);
                        writer.RenderEndTag();  


                     
                        base.Render(writer);
                }
                public   virtual   void   RaisePostBackEvent(string   eventArgument)
                {
                      OnBlurThis(new   EventArgs());
                }
                public   event   EventHandler   OnBlur;
       

                protected   virtual   void   OnBlurThis(EventArgs   e)
                {
                        if   (OnBlur   !=   null)
                        {
                                OnBlur(this,   null);

                        }



                }
   

     
        }
}


[解决办法]
沙发,帮你顶
[解决办法]
学习 帮你顶。

[解决办法]
继续帮你顶,楼上的厉害啊......
[解决办法]
帮顶

热点排行