/
DynamicAddControl.ascx.cs
121 lines (86 loc) · 3.59 KB
/
DynamicAddControl.ascx.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
namespace Innovaction.Modules.CustomerCreate
{
public partial class DynamicAddControl : System.Web.UI.UserControl
{
public List<ChildrenControl> ChildControlList = new List<ChildrenControl>();
string ChildControlURL = "~/desktopmodules/CustomerCreate/ChildrenControl.ascx";
protected void Page_Load(object sender, EventArgs e)
{
if (IsPostBack)
{
string fieldCount = tx_Qty.Text;
int count = string.IsNullOrEmpty(fieldCount) ? 0 : Convert.ToInt32(fieldCount);
for (int i = 0; i < count; i++)
{
CreateTextBoxSet(i, DynamicPlaceHolder);
}
}
}
protected void Add_Click(object sender, EventArgs e)
{
string fieldCount = tx_Qty.Text;
int count = string.IsNullOrEmpty(fieldCount) ? 0 : Convert.ToInt32(fieldCount);
var MyControl = Add();
MyControl.SelectedDate = DDD_picker.SelectedValue;
MyControl.SelectedGender = dd_gender.SelectedValue;
MyControl.SelectedKid = count + 1;
}
void CreateTextBoxSet(int count, PlaceHolder holder)
{
//PlaceHolder MyControl = new PlaceHolder();
//MyControl.ID = "SubHolder_" + count;
//for (int i = 0; i < 3; i++)
//{
// TextBox txt1 = new TextBox();
// Literal lit1 = new Literal();
// txt1.ID = "Literal_" + i + "_" + count;
// lit1.ID = "TextBox_" + i + "_" + count;
// lit1.Text = " <br/>";
// MyControl.Controls.Add(txt1);
// MyControl.Controls.Add(lit1);
//}
ChildrenControl MyControl = (ChildrenControl)Page.LoadControl(ChildControlURL);
MyControl.ID = "ChildControl_" + count;
ChildControlList.Add(MyControl);
holder.Controls.Add(MyControl);
}
public ChildrenControl Add()
{
string fieldCount = tx_Qty.Text;
int count = string.IsNullOrEmpty(fieldCount) ? 0 : Convert.ToInt32(fieldCount);
ChildrenControl MyControl = (ChildrenControl)Page.LoadControl(ChildControlURL);
MyControl.ID = "ChildControl_" + count;
count++;
ChildControlList.Add(MyControl);
DynamicPlaceHolder.Controls.Add(MyControl);
tx_Qty.Text = count.ToString();
return MyControl;
}
//protected void Add_Click(object sender, EventArgs e)
//{
// //List<ChildrenControl> myList = new List<ChildrenControl>();
// ////// redibujo los anteriores
// //foreach (ChildrenControl prevControl in DynamicControls.Controls)
// //{
// // myList.Add(prevControl);
// //}
// //foreach (var myCont in myList)
// //{
// // DynamicControls.Controls.Add(myCont);
// //}
// //DynamicControls.Controls.Count;
// // agrego el nuevo control
// TextBox ToAdd = new TextBox();
// ToAdd.ID = "Test_" + DynamicControls.Controls.Count.ToString();
// DynamicControls.Controls.Add(ToAdd);
// // ControlList.Add(ToAdd);
// tx_Qty.Text = DynamicControls.Controls.Count.ToString();
//}
}
}