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"] = value;
}
}
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!