I am having a weird experience. I am dynamically creating a row of textboxes at runtime when the user clicks a button.
However, on my local machine the text boxes appear correctly (example
[TextBox1] [TextBox2] [TextBox3] [TextBox4] [TextBox5]
[TextBox1] [TextBox2] [TextBox3] [TextBox4] [TextBox5]
[TextBox1] [TextBox2] [TextBox3] [TextBox4] [TextBox5]
When I run this app on the production, the output side-by-side is:
[TextBox1][TextBox1] [TextBox2][TextBox2] [TextBox3][TextBox3] [TextBox4][TextBox4]
The output should be one row of textboxes, then a second row of 5 text boxes etc.
The code that builds the textboxes is:
protected override void OnInit(EventArgs e)
{
base.OnInit(e);
dyntxtCar = new TextBox[myCount];
dyntxtMake = new TextBox[myCount];
dyntxtMileage = new TextBox[myCount];
dyntxtVIN = new TextBox[myCount];
dyntxtSLIC = new TextBox[myCount];
dyntxtPlateNumber = new TextBox[myCount];
for (i = 0; i < myCount; i += 1)
{
TextBox txtCar = new TextBox();
TextBox txtMake = new TextBox();
TextBox txtMileage = new TextBox();
TextBox txtVIN = new TextBox();
TextBox txtSLIC = new TextBox();
TextBox txtPlateNumber = new TextBox();
txtCar.ID = "txtVehCar" + i.ToString();
txtMake.ID = "txtVehMake" + i.ToString();
txtMileage.ID = "txtVehMilage" + i.ToString();
txtVIN.ID = "txtVehVIN" + i.ToString();
txtSLIC.ID = "txtVehSLIC" + i.ToString();
txtPlateNumber.ID = "txtVehPlate" + i.ToString();
//Set tabIndex values for dynamic text fields;
txtCar.TabIndex = System.Convert.ToInt16(i * 10 + 1);
txtMake.TabIndex = System.Convert.ToInt16(i * 10 + 2);
txtMileage.TabIndex = System.Convert.ToInt16(i * 10 + 3);
txtVIN.TabIndex = System.Convert.ToInt16(i * 10 + 4);
txtSLIC.TabIndex = System.Convert.ToInt16(i * 10 + 5);
txtPlateNumber.TabIndex = System.Convert.ToInt16(i * 10 + 6);
//Set maxlength for dynamic fields;
txtCar.MaxLength = System.Convert.ToInt16(7);
txtVIN.MaxLength = System.Convert.ToInt16(17);
txtSLIC.MaxLength = System.Convert.ToInt16(4);
//Set width of text boxes
txtCar.Width = System.Convert.ToInt16("65");
txtMileage.Width = System.Convert.ToInt16("50");
txtVIN.Width = System.Convert.ToInt16("220");
txtSLIC.Width = System.Convert.ToInt16("45");
//txtPlateNumber.Width = System.Convert.ToInt16("35");
phCar.Controls.Add(txtCar);
phMake.Controls.Add(txtMake);
phMileage.Controls.Add(txtMileage);
phVIN.Controls.Add(txtVIN);
phSLIC.Controls.Add(txtSLIC);
phPlateNumber.Controls.Add(txtPlateNumber);
dyntxtCar[i] = txtCar;
dyntxtMake[i] = txtMake;
dyntxtMileage[i] = txtMileage;
dyntxtVIN[i] = txtVIN;
dyntxtSLIC[i] = txtSLIC;
dyntxtPlateNumber[i] = txtPlateNumber;
LiteralControl literalBreak = new LiteralControl("<br />");
phCar.Controls.Add(literalBreak);
phMake.Controls.Add(literalBreak);
phMileage.Controls.Add(literalBreak);
phVIN.Controls.Add(literalBreak);
phSLIC.Controls.Add(literalBreak);
phPlateNumber.Controls.Add(literalBreak);
}
}
protected void Page_PreInit(object sender, EventArgs e)
{
Control myControl = GetPostBackControl(this.Page);
if ((myControl != null))
{
if ((myControl.ClientID.ToString() == "btnAddTextBox"))
{
myCount = myCount + 1;
}
}
}
public static Control GetPostBackControl(Page thePage)
{
Control myControl = null;
string ctrlName = thePage.Request.Params.Get("__EVENTTARGET");
if (((ctrlName != null) & (ctrlName != string.Empty)))
{
myControl = thePage.FindControl(ctrlName);
}
else
{
foreach (string Item in thePage.Request.Form)
{
Control c = thePage.FindControl(Item);
if (((c) is System.Web.UI.WebControls.Button))
{
myControl = c;
}
}
}
return myControl;
}
Anyone experience this?