S
Stef
I folks,
I have a simple page with a user control dropped on it, a textbox
and a submit button.
That usercontrol should display the value entered in a textbox after
I've clicked the submit button but it doesn't on the first click! I
must click a second time to get the textbox value displayed in my
usercontrol! If I change the value in the textbox on each postback,
that value will always be displayed 2 clicks after!
Someone can help on this one?
Thanks!
Here's my code: (Note it's a test page to reproduce the problem)
Page code:
public class WebForm1 : System.Web.UI.Page
{
protected System.Web.UI.WebControls.TextBox TextBox1;
protected System.Web.UI.WebControls.Button Button1;
private void Page_Load(object sender, System.EventArgs e)
{
LoadControls();
}
private void LoadControls()
{
test1 ts1 =
(test1)FindControl("test11");//(test1)LoadControl("test1.ascx");
ts1.ID = "aa";
ts1.Text = (string)ViewState["ts1Text"];
}
#region Code généré par le Concepteur Web Form
override protected void OnInit(EventArgs e)
{
//
// CODEGEN : Cet appel est requis par le Concepteur Web Form
ASP.NET.
//
InitializeComponent();
base.OnInit(e);
if (ViewState["ts1Text"]==null) ViewState["ts1Text"]=string.Empty;
}
/// <summary>
/// Méthode requise pour la prise en charge du concepteur - ne
modifiez pas
/// le contenu de cette méthode avec l'éditeur de code.
/// </summary>
private void InitializeComponent()
{
this.Button1.Click += new System.EventHandler(this.Button1_Click);
this.Load += new System.EventHandler(this.Page_Load);
}
#endregion
private void Button1_Click(object sender, System.EventArgs e)
{
ViewState["ts1Text"] = TextBox1.Text;
}
}
Usercontrol code:
public class test1 : System.Web.UI.UserControl
{
protected System.Web.UI.WebControls.Label Label1;
public string Text
{
get
{
return (string)ViewState["Text"];
}
set
{
ViewState["Text"] = value;
}
}
private void Page_Load(object sender, System.EventArgs e)
{
Label1.Text = Text;
}
#region Code généré par le Concepteur Web Form
override protected void OnInit(EventArgs e)
{
//
// CODEGEN : Cet appel est requis par le Concepteur Web Form
ASP.NET.
//
InitializeComponent();
base.OnInit(e);
}
/// <summary>
/// Méthode requise pour la prise en charge du concepteur - ne
modifiez pas
/// le contenu de cette méthode avec l'éditeur de code.
/// </summary>
private void InitializeComponent()
{
this.Load += new System.EventHandler(this.Page_Load);
}
#endregion
}
I have a simple page with a user control dropped on it, a textbox
and a submit button.
That usercontrol should display the value entered in a textbox after
I've clicked the submit button but it doesn't on the first click! I
must click a second time to get the textbox value displayed in my
usercontrol! If I change the value in the textbox on each postback,
that value will always be displayed 2 clicks after!
Someone can help on this one?
Thanks!
Here's my code: (Note it's a test page to reproduce the problem)
Page code:
public class WebForm1 : System.Web.UI.Page
{
protected System.Web.UI.WebControls.TextBox TextBox1;
protected System.Web.UI.WebControls.Button Button1;
private void Page_Load(object sender, System.EventArgs e)
{
LoadControls();
}
private void LoadControls()
{
test1 ts1 =
(test1)FindControl("test11");//(test1)LoadControl("test1.ascx");
ts1.ID = "aa";
ts1.Text = (string)ViewState["ts1Text"];
}
#region Code généré par le Concepteur Web Form
override protected void OnInit(EventArgs e)
{
//
// CODEGEN : Cet appel est requis par le Concepteur Web Form
ASP.NET.
//
InitializeComponent();
base.OnInit(e);
if (ViewState["ts1Text"]==null) ViewState["ts1Text"]=string.Empty;
}
/// <summary>
/// Méthode requise pour la prise en charge du concepteur - ne
modifiez pas
/// le contenu de cette méthode avec l'éditeur de code.
/// </summary>
private void InitializeComponent()
{
this.Button1.Click += new System.EventHandler(this.Button1_Click);
this.Load += new System.EventHandler(this.Page_Load);
}
#endregion
private void Button1_Click(object sender, System.EventArgs e)
{
ViewState["ts1Text"] = TextBox1.Text;
}
}
Usercontrol code:
public class test1 : System.Web.UI.UserControl
{
protected System.Web.UI.WebControls.Label Label1;
public string Text
{
get
{
return (string)ViewState["Text"];
}
set
{
ViewState["Text"] = value;
}
}
private void Page_Load(object sender, System.EventArgs e)
{
Label1.Text = Text;
}
#region Code généré par le Concepteur Web Form
override protected void OnInit(EventArgs e)
{
//
// CODEGEN : Cet appel est requis par le Concepteur Web Form
ASP.NET.
//
InitializeComponent();
base.OnInit(e);
}
/// <summary>
/// Méthode requise pour la prise en charge du concepteur - ne
modifiez pas
/// le contenu de cette méthode avec l'éditeur de code.
/// </summary>
private void InitializeComponent()
{
this.Load += new System.EventHandler(this.Page_Load);
}
#endregion
}