做了一个输入框控件:
[DefaultProperty("Text")]
    [ToolboxData("<{0}:ttttttt runat=server></{0}:ttttttt>")]
    public class ttttttt: WebControl
    {
        [Bindable(true)]
        [Category("Appearance")]
        [DefaultValue("")]
        [Localizable(true)]
        public string Text
        {
            get
            {
                String s = (String)ViewState["Text"];
                return ((s == null)? String.Empty : s);
            }
 
            set
            {
                ViewState["Text"] = value;
            }
        }        public ttttttt()
            : base(HtmlTextWriterTag.Input)
        { }        protected override void AddAttributesToRender(HtmlTextWriter writer)
        {
            base.AddAttributesToRender(writer);
            writer.AddAttribute(HtmlTextWriterAttribute.Type, "text");
            writer.AddAttribute(HtmlTextWriterAttribute.Value, Text);
        }
=================
可是在后台取不到输入的值!

解决方案 »

  1.   

    public class ttttttt: WebControl.TextBox 
    试试.
      

  2.   


    if(Page.IsPostBack && Request.Pamas[this.UniqueID]!= null )
    {
       this.Text = Request.Pamas[this.UniqueID];
    }把这段代码放在OnLoadViewstata之前,
      

  3.   

    或是在重写Load的时候,并且这时要触发TextChanged事件
      

  4.   

    ....想了下,
    只要写在OnSaveViewState之前,并且在你读取该值之前均可,
    如果你要在Page_Load中读取,你要写在Control.Load事件发生之前,其它的倒没有什么要紧的
      

  5.   

    你们人这些原因也不想想,就知道顶,何来讨论楼主的 public string Text
            {
                get
                {
                    String s = (String)ViewState["Text"];
                    return ((s == null)? String.Empty : s);
                }
     
                set
                {
                    ViewState["Text"] = value;
                }
            }
    这段代码很清楚的表示,Text属性只有其它代码给它值的时候才会记录当用户改变了值,然后点击submit按钮,谁来改变这个值,这个值依然还是上次给他的那个值
    这时应该 看它的值是否在Request 列表中并且在submit之后由自己给
      

  6.   

    zyug(LovlyPuppy) : 对呀,我就想知道javascript中能吧值存到SESSION吗?
      

  7.   

    hdt(倦怠) 的方法是对的,我把源代码贴出来供大家参考吧:
     public String Text
            {
                get
                {
                    return (String)ViewState["Text"];
                }            set
                {
                    ViewState["Text"] = value;
                }
            }        public ttttttt()
                : base(HtmlTextWriterTag.Input)
            { }        public event EventHandler TextChanged;        public virtual bool LoadPostData(string postDataKey,
               NameValueCollection postCollection)
            {            String presentValue = Text;
                String postedValue = postCollection[postDataKey];            if (presentValue == null || !presentValue.Equals(postedValue))
                {
                    Text = postedValue;
                    return true;
                }            return false;
            }        public virtual void RaisePostDataChangedEvent()
            {
                OnTextChanged(EventArgs.Empty);
            }        protected virtual void OnTextChanged(EventArgs e)
            {
                if (TextChanged != null)
                    TextChanged(this, e);
            }        protected override void AddAttributesToRender(HtmlTextWriter writer)
            {
                writer.AddAttribute(HtmlTextWriterAttribute.Type, "input");
                writer.AddAttribute(HtmlTextWriterAttribute.Value, Text);
                writer.AddAttribute(HtmlTextWriterAttribute.Name, this.UniqueID);
            }
    ==========================
     writer.AddAttribute(HtmlTextWriterAttribute.Name, this.UniqueID);
    这行比较重要!