How to store the dynamically generated controls ?
I have generated controls now i want to store those controls and also want to store the user's input enetered in the generated controls into the database.How to do it.Code is appreciated(C#).Below is the code given to generate dynamic controls on each button click.
protected void Button4_Click(object sender, EventArgs e)
{
Panel3.Visible = true;
T = "U";
try
{
StreamWriter writer = File.AppendText(@"C:\asp\f.txt");
writer.WriteLine("U");
writer.Close();
}
catch (IOException io)
{
throw new IOException(io.Message);
}
k++;
Addit();
T = "";
k1 = k1 + 1;
}
protected void Button6_Click(object sender, EventArgs e)
{
Panel5.Visible = true;
T = "C";
try
{
StreamWriter writer = File.AppendText(@"C:\asp\f.txt");
writer.WriteLine("C");
writer.Close();
}
catch (IOException io)
{
throw new IOException(io.Message);
}
k++;
Addit();
T = "";
k1 = k1 + 1;
}
protected void Button10_Click(object sender, EventArgs e)
{
Panel7.Visible = true;
T = "T";
try
{
StreamWriter writer = File.AppendText(@"C:\asp\f.txt");
writer.WriteLine("T");
// File.GetCreationTime();
writer.Close();
}
catch (IOException io)
{
throw new IOException(io.Message);
}
k++;
Addit();
T = "";
k1 = k1 + 1;
}
public void Addit()
{
try
{
string ln;
int i = 0;
StreamReader tr = new StreamReader(@"C:\asp\f.txt");
ln = tr.ReadLine();
while (ln != null)
{
// Response.Write(ln);
if (ln == "T")
{
string s = string.Empty;
l = new Label();
t = new TextBox();
//s=name[(k-1)];
s = "l";
s += i.ToString();
l.ID = s;
//l.Font.Bold = true;
l.Style["Position"] = "Absolute";
//l.Style["Top"] = "25px";
l.Style["Left"] = "10px";
//l.Style.Add["bold", "true"];
l.Text = TextBox11.Text;
l.EnableViewState = true;
//l.EnableViewState = false;
s = string.Empty;
s = "t";
s += i.ToString();
t.ID = s;
s = string.Empty;
s = "Text";
s += i.ToString();
//t.Text = s;
t.Style["Position"] = "Absolute";
//t.Style["Top"] = "25px";
t.Style["Left"] = "100px";
t.EnableViewState = true;
//t.EnableViewState = false;
LiteralControl lc = new LiteralControl();
lc.Text = "<BR><BR>";
Panel4.Controls.Add(l);
Panel4.Controls.Add(t);
Panel4.Controls.Add(lc);
}
else if (ln == "U")
{
string s = string.Empty;
l2 = new Label();
t2 = new TextBox();
//s=name[(k-1)];
s = "l2";
s += i.ToString();
l2.ID = s;
//l2.Font.Bold = true;
l2.Style["Position"] = "Absolute";
//l.Style["Top"] = "25px";
l2.Style["Left"] = "10px";
l2.EnableViewState = true;
s = string.Empty;
s = " Descriptors";
s += i.ToString();
l2.Text = TextBox6.Text;
s = string.Empty;
s = "t2";
s += i.ToString();
t2.ID = s;
s = string.Empty;
s = "Text";
s += i.ToString();
//te.Text = s;
t2.Style["Position"] = "Absolute";
//t.Style["Top"] = "25px";
t2.Style["Left"] = "100px";
t2.EnableViewState = true;
LiteralControl lc = new LiteralControl();
lc.Text = "<BR><BR>";
Panel4.Controls.Add(l2);
Panel4.Controls.Add(t2);
Panel4.Controls.Add(lc);
}
else if (ln == "C")
{
string s = string.Empty;
l3 = new Label();
t3 = new TextBox();
dl = new DropDownList();
s = "l3";
s += i.ToString();
l3.ID = s;
//l3.Font.Bold = true;
l3.Style["Position"] = "Absolute";
//l.Style["Top"] = "25px";
l3.Style["Left"] = "10px";
l3.EnableViewState = true;
s = string.Empty;
s = " Choices";
s += i.ToString();
l3.Text = TextBox8.Text;
s = string.Empty;
s = "t3";
s += i.ToString();
t3.ID = s;
s = string.Empty;
s = "Text";
s += i.ToString();
//tex.Text = s;
t3.Style["Position"] = "Absolute";
//t.Style["Top"] = "25px";
t3.Style["Left"] = "100px";
t3.EnableViewState = true;
s = string.Empty;
s = " List";
s += i.ToString();
dl.ID = s;
dl.Style["Position"] = "Absolute";
//l.Style["Top"] = "25px";
dl.Style["Left"] = "260px";
dl.Width = 150;
dl.EnableViewState = true;
LiteralControl lc = new LiteralControl();
lc.Text = "<BR><BR>";
Panel4.Controls.Add(l3);
Panel4.Controls.Add(t3);
Panel4.Controls.Add(dl);
Panel4.Controls.Add(lc);
}
else if (ln == "F")
{
string s = string.Empty;
l4 = new Label();
t4 = new TextBox();
lb = new ListBox();
s = "l4";
s += i.ToString();
l4.ID = s;
//l4.Font.Bold = true;
l4.Style["Position"] = "Absolute";
//l.Style["Top"] = "25px";
l4.Style["Left"] = "10px";
s = string.Empty;
s = " Choices1";
//s += i.ToString();
l4.Text = TextBox9.Text;
l4.EnableViewState = true;
s = string.Empty;
s = "t4";
s += i.ToString();
t4.ID = s;
s = string.Empty;
s = "T4";
s += i.ToString();
//text.Text = s;
t4.Style["Position"] = "Absolute";
//t.Style["Top"] = "25px";
t4.Style["Left"] = "100px";
t4.EnableViewState = true;
s = string.Empty;
s = " ListBox";
s += i.ToString();
lb.ID = s;
//dl.ID = s;
lb.Style["Position"] = "Absolute";
////dl.Style["Position"] = "Absolute";
////l.Style["Top"] = "25px";
lb.Style["Left"] = "260px";
//dl.Style["Left"] = "260px";
lb.Width = 150;
lb.Height = 100;
//dl.Width = 150;
lb.EnableViewState = true;
LiteralControl lc = new LiteralControl();
lc.Text = "<BR><BR><BR><BR><BR>";
Panel4.Controls.Add(l4);
Panel4.Controls.Add(t4);
Panel4.Controls.Add(lb);
Panel4.Controls.Add(lc);
}
ln = tr.ReadLine();
i++;
}
tr.Close();
}
catch (IOException io)
{
throw new IOException(io.Message);
}
}
|