Adding multiple control in aspx page

Hi , i have a requirement where user can add multiple work experience means there is block in which 4 text boxes are present like company name, position, technology and working period.Now there is an option for user to "Add Another" work experience.When the user will click on "Add Another" that time another set of 4 text boxes will be opened.Now my concern is that i have no idea how many times the user will click on the "Add Another " option.There is no restriction for the end user.Initially i have planned to create 4 sets of control in which one will be remain opened and rest will be in hide .So when the user will click on the "Add Another " option i ll open the text box set 1 by 1.But when i checked with my manager he is saying there is no limitation.So it is very hard for me to manage all.What i like to develop it should be created on the fly and i want to store the data in XML format and when the user will click on the  final submit button i will store the data in a single submit click to avoid the database round trip of all control's data.But my concern is that if i ll create a user control of 4 text boxes , could i call the user control or lead the user control unlimited time.Now another issue of page post back and view state.I need a best possible solution to achieve my target to crate control dynamically and store the data in the database in best possible way.
tanu80Asked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

 
plusone3055Commented:
You manager may not be technically sound (no offense) I would suggest you use your judgement and set the limit to 100 (or far less) .. anyone that has 100 jobs and applying for another one needs help ;)

0
 
HainKurtSr. System AnalystCommented:
put a limitation on "add another" say 10...
and each time set a hidden varieble to store the count... add items dynamically (change names on the fly using the current counter value (say Exp3, exp3_dateFrom, exp3_DateTo,...) using jQuery or js DOM
all is on client... when user submits finally, you will have some counters in hidden values

<input type=hidden name=expCount />

on posted value, get this count, say 5
then loop your request items like

loop i=1 to Request("expCount ")
  dim exp = Request("Exp" & i)  
  dim expFrom = Request("Exp" & i &"_DateFrom")
  dim expTo = Request("Exp" & i &"_DateTo")
  ...
  and post to db
end loop
0
 
magadesign_sviluppoCommented:
hi,
I would have done like this:
page.aspx
<asp:ListView runat="server" ID="LV" OnItemCommand="LV_ItemCommand">
	<ItemTemplate>
		<table>
			<tr>
				<td class="selected_delete">
					<asp:LinkButton ID="lnk_del" runat="server" CommandName="del"></asp:LinkButton>
				</td>
				<td class="selected_num">
					<asp:Label ID="lbl_id" runat="server" Text='<%# Eval("id") %>'></asp:Label>
				</td>
				<td class="selected_text">
					<asp:TextBox ID="txt1" runat="server" Text='<%# Eval("txt1") %>' Width="300"></asp:TextBox>
				</td>
				<td class="selected_text">
					<asp:TextBox ID="txt2" runat="server" Text='<%# Eval("txt2") %>' Width="300"></asp:TextBox>
				</td>
				<td class="selected_text">
					<asp:TextBox ID="txt3" runat="server" Text='<%# Eval("txt3") %>' Width="300"></asp:TextBox>
				</td>
				<td class="selected_text">
					<asp:TextBox ID="txt4" runat="server" Text='<%# Eval("txt4") %>' Width="300"></asp:TextBox>
				</td>
			</tr>
		</table>
	</ItemTemplate>
	<LayoutTemplate>
		<table id="itemPlaceholder" runat="server" />
	</LayoutTemplate>
</asp:ListView>
<table class="selected_item">
	<tr>
		<td>
			<asp:LinkButton ID="lnk_addItem" runat="server" OnClick="lnk_addItem_Click">
				Add Item
			</asp:LinkButton>
		</td>
	</tr>
</table>

Open in new window


page.aspx.cs
protected class myControls
{
	public int id { get; set; }
	public string txt1 { get; set; }
	public string txt2 { get; set; }
	public string txt3 { get; set; }
	public string txt4 { get; set; }
	public myControls(int _id, string _txt1, string _txt2, string _txt3, string _txt4)
	{
		id = _id;
		txt1 = _txt1;
		txt2 = _txt2;
		txt3 = _txt3;
		txt4 = _txt4;
	}
}
protected void lnk_addItem_Click(object sender, EventArgs e)
{
	List<myControls> _list = new List<myControls>();
	foreach (ListViewDataItem _item in LV.Items)
	{
		TextBox txt1 = _item.FindControl("txt1") as TextBox;
		TextBox txt2 = _item.FindControl("txt2") as TextBox;
		TextBox txt3 = _item.FindControl("txt3") as TextBox;
		TextBox txt4 = _item.FindControl("txt4") as TextBox;
		Label lbl = _item.FindControl("lbl_id") as Label;
		if (txt != null && lbl != null)
		{
			_list.Add(new myControls(_list.Count + 1, txt1.Text, txt2.Text, txt3.Text, txt4.Text));
		}
	}
	_list.Add(new myControls(_list.Count + 1, "", "", "", ""));
	LV.DataSource = _list;
	LV.DataBind();
}

protected void LV_ItemCommand(object sender, ListViewCommandEventArgs e)
{
	TextBox txt1 = null;
	TextBox txt2 = null;
	TextBox txt3 = null;
	TextBox txt4 = null;
	Label lbl = null;
	List<myControls> _list = new List<myControls>();
	List<myControls> _listOld = new List<myControls>();
	foreach (ListViewDataItem _item in LV.Items)
	{
		txt1 = _item.FindControl("txt1") as TextBox;
		txt2 = _item.FindControl("txt2") as TextBox;
		txt3 = _item.FindControl("txt3") as TextBox;
		txt4 = _item.FindControl("txt4") as TextBox;
		if (txt != null && lbl != null)
		{
			_listOld.Add(new myControls(lbl.Text.ToInt32(), txt1.Text, txt2.Text, txt3.Text, txt4.Text));
		}
	}
	lbl = e.Item.FindControl("lbl_id") as Label;
	if (txt != null && lbl != null)
	{
		myControls _sel = _listOld.SingleOrDefault(x => x.ID == lbl.Text.ToInt32());
		if (_sel != null)
			_listOld.Remove(_sel);
	}
	foreach (myControls _control in _listOld)
	{
		_list.Add(new myControls(_list.Count + 1, _control.txt1, _control.txt2, _control.txt3, _control.txt4));
	}
	LV.DataSource = _list;
	LV.DataBind();
}
protected void Save()
{
	TextBox txt1 = null;
	TextBox txt2 = null;
	TextBox txt3 = null;
	TextBox txt4 = null;
	Label lbl = null;
	List<myControls> _list = new List<myControls>();
	foreach (ListViewDataItem _item in LV.Items)
	{
		txt1 = _item.FindControl("txt1") as TextBox;
		txt2 = _item.FindControl("txt2") as TextBox;
		txt3 = _item.FindControl("txt3") as TextBox;
		txt4 = _item.FindControl("txt4") as TextBox;
		if (txt != null && lbl != null)
		{
			_list.Add(new myControls(lbl.Text.ToInt32(), txt1.Text, txt2.Text, txt3.Text, txt4.Text));
		}
	}
	// do something with the list
}

Open in new window

i have modified code i already had, may have errors, didn't test.
hope it helps
0

Experts Exchange Solution brought to you by ConnectWise

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
 
magadesign_sviluppoCommented:
ooops :)
forgoten
protected void Page_Load(object sender, EventArgs e)
{
	DC_RENTAL = maga_DataContext.DC_RENTAL;
	if (!IsPostBack)
	{
		List<myControls> _list = new List<myControls>();
		_list.Add(new myControls(_list.Count + 1, "", "", "", "")); // one 
		//_list.Add(new myControls(_list.Count + 1, "", "", "", "")); // or two items initial
		LV.DataSource = _list;
		LV.DataBind();
	}
}

Open in new window

0
 
tanu80Author Commented:
good one
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.