Ritesh Singh

Ritesh Singh

  • NA
  • 114
  • 41.2k

Not Find the control to show the value in textbox in c#

Apr 2 2014 3:34 AM
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Gutil;
public partial class dynamicform1 : System.Web.UI.Page
{
string strValue = string.Empty;
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
// CreateTextBoxes();
//ViewState["count"] = 1;
}
btnSubmit.Visible = false;
}
protected void btnGenerate_Click(object sender, EventArgs e)
{
CreateTextBoxes();
}
protected void btnSubmit_Click(object sender, EventArgs e)
{
strValue = string.Empty;
string values = txtFields.Text;
string[] value = values.Split(',');
int n =value.Count();
for (int i = 0; i <= n; i++)
{
// value[i].Text = "txt" + value[i].ToString();
string boxName = "txt" + (i + 1).ToString();
TextBox txt = phTextBoxes.FindControl(boxName) as TextBox;`enter code here`
strValue += txt.Text + "\n";
//btnSubmit.Click += new EventHandler(btnSubmit_Click);
}
Response.Write(values);
}
private void CreateTextBoxes()
{
string values = txtFields.Text;
string[] value = values.Split(',');
for (int j = 0; j < value.Count(); j++)
{
TextBox txt = new TextBox();
//Add berek so the next textbox will create in next new line
Literal lit = new Literal();
lit.Text = "<br><br>";
Label lbl = new Label();
txt.ID = "txt" + value[j];
txt.EnableViewState = true;
//btnGenerate.Click += new EventHandler(btnGenerate_Click);
lbl.ID = "lbl" + value[j];
lbl.Text = value[j] + ": ";`enter code here`
form1.Controls.Add(lbl);
form1.Controls.Add(txt);
form1.Controls.Add(lit);
panelform.Controls.Add(lbl);
panelform.Controls.Add(txt);
panelform.Controls.Add(lit);`enter code here`
panelform.Controls.Add(btnSubmit);
}
panelform.Visible = true;
btnSubmit.Visible = true;
}
}
enter code here

Answers (1)