Hi All,
I am trying to use a user control in one of my pages.
I have not been able to access the variable that are set during the execution on the Control.
Basically the contol allows a user to select a row from a datagrid.
The Primary key of that record is recorded in a private variable.
I then access the private variable with an Accessor.
This works fine with any default values in variables, but not when the value has changed through the execution of the controls purpose, only default values show.
I have been guessing that this is somehow related to the control not maintaining state but I am not sure what to do.
I have contructed a simple User Control to simplify the issue but still have the same problem.
Can saomeone please take a look at my logic and let me know where I am going wrong.
The simplified user control code is as below
Code:
public class TestControl : System.Web.UI.UserControl
{
protected System.Web.UI.WebControls.TextBox TextBox1;
protected System.Web.UI.WebControls.TextBox TextBox2;
protected System.Web.UI.WebControls.Button Button1;
public string Concat = string.Empty;
private void Page_Load(object sender, System.EventArgs e)
{
// Put user code to initialize the page here
}
private void Button1_Click(object sender, System.EventArgs e)
{
Concat = TextBox1.Text + " " + TextBox2.Text;
}
#region Web Form Designer generated code
override protected void OnInit(EventArgs e)
{
//
// CODEGEN: This call is required by the ASP.NET Web Form Designer.
//
InitializeComponent();
base.OnInit(e);
}
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
this.Button1.Click += new System.EventHandler(this.Button1_Click);
this.Load += new System.EventHandler(this.Page_Load);
}
#endregion
}
including generated code
The code for the web page to access this is
Code:
protected UserControls.TestControl TestControl1;
private void Page_Load(object sender, System.EventArgs e)
{
Response.Write("CONCAT = " + TestControl1.Concat);
}
and I have an instance of my TestControl in the aspx page.
I understand that being in the page load does not allow any values the first time round, but when I add values and Concatinate them with the control, it still doesn't show.
I hope Ive been clear enough with my problem here.
Any assistance would be greatly appreciated.
======================================
They say, best men are molded out of faults,
And, for the most, become much more the better
For being a little bad.
======================================