开发者

recreate the textbox asp.net server control

I am trying to recreate the TextBox control, the problem is that after the postback the value in the textbox returns to it's initial state.

Anybody knows how to make it persist the value after postbacks ?

    [DefaultProperty("Text")]
    [ToolboxData("<{0}:MyTextBox runat=server></{0}:MyTextBox>")]
    public class MyTextBox : WebControl
    {

        [Bindable(true)]
        [DefaultValue("")]
        public string Text
        {
            get
            {
                return (String)ViewState["Text"] ?? string.Empty;
            }

            set
            {
                ViewState["Text"] = valu开发者_运维问答e;
            }
        }


        protected override void RenderContents(HtmlTextWriter output)
        {
            var a = string.Format(@"<input type='text' id='{0}' name='{0}' value='{1}' />", ID, Text);

          output.Write(a);
        }

        protected override void Render(HtmlTextWriter writer)
        {
            RenderContents(writer);
        }
    }


Your input doesn't have a name... Without a name his value will never posted back!

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜