P
Paul
Hi all,
I have a simple custom control with a label and a text box. The text
control's value is persisting when I do a post back, so the view state
is working, but I cannot access the value in the code. Is there
anything different I have to do to expose the value of the text box?
testControl.Text returns the unchanged original value, not the new
value.
Thanks,
Paul
using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
namespace Test
{
public class TestControl : Control, INamingContainer
{
protected Label label;
protected TextBox textBox;
public string Title
{
get { return (string)ViewState["Title"]; }
set { ViewState["Title"] = value; }
}
public string Text
{
get { return (string)ViewState["Text"]; }
set { ViewState["Text"] = value; }
}
protected override void CreateChildControls()
{
TableRow row = new TableRow();
Controls.Add(row);
TableCell cell = new TableCell();
row.Controls.Add(cell);
label = new Label();
label.EnableViewState = false;
label.Text = Title;
cell.Controls.Add(label);
cell.Controls.Add(new LiteralControl(" "));
textBox = new TextBox();
textBox.Text = Text;
Page.Response.Write(textBox.Text);
cell.Controls.Add(textBox);
}
}
}
I have a simple custom control with a label and a text box. The text
control's value is persisting when I do a post back, so the view state
is working, but I cannot access the value in the code. Is there
anything different I have to do to expose the value of the text box?
testControl.Text returns the unchanged original value, not the new
value.
Thanks,
Paul
using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
namespace Test
{
public class TestControl : Control, INamingContainer
{
protected Label label;
protected TextBox textBox;
public string Title
{
get { return (string)ViewState["Title"]; }
set { ViewState["Title"] = value; }
}
public string Text
{
get { return (string)ViewState["Text"]; }
set { ViewState["Text"] = value; }
}
protected override void CreateChildControls()
{
TableRow row = new TableRow();
Controls.Add(row);
TableCell cell = new TableCell();
row.Controls.Add(cell);
label = new Label();
label.EnableViewState = false;
label.Text = Title;
cell.Controls.Add(label);
cell.Controls.Add(new LiteralControl(" "));
textBox = new TextBox();
textBox.Text = Text;
Page.Response.Write(textBox.Text);
cell.Controls.Add(textBox);
}
}
}