I'm trying to add another eventHandler to RadioButton. This is the sample code (which is working):
ASP.NET:
<asp:Label ID="Label1" runat="server" Text="Label"></asp:Label>
<asp:PlaceHolder ID="PlaceHolder1" runat="server"></asp:PlaceHolder>
<asp:Button ID="Button1" runat="server" Text="Button" />
C#:
protected void Page_Load(object sender, EventArgs e)
{
RadioButton RB1 = new RadioButton();
RB1.ID = "1";
RB1.GroupName = "bla";
RB1.CheckedChanged += new EventHandler(CheckedChanged);
RadioButton RB2 = new RadioButton();
RB2.ID = "2";
RB2.GroupName = "bla";
RB2.CheckedChanged += new EventHandler(CheckedChanged);
PlaceHolder1.Controls.Add(RB1);
PlaceHolder1.Controls.Add(RB2);
}
protected void CheckedChanged(object sender, EventArgs e)
{
Label1.Text = ((RadioButton)sender).ID;
}
In my project I have dynamic creating of RadioButtons (the number of rows I get from database). The same adding eventHandler does not work, but if I write
MyRadioButton.Load += new EventHandler(Another_method);
The Another_method will start, but in
MyRadioButton.CheckedChanged += new EventHandler(Main_method);
the Main_method will not start if I choose one of the RadioButtons.
What is wrong?
#KevinP
This is my code:
Table tb1 = new Table();
PlaceHolder1.Controls.Add(tb1);
TableRow tr = new TableRow();
TableCell tc = new TableCell();
//adding the first row with title"
tr.Cells.Add(tc);
for (int i = 0; i < ((ArrayList)(result[0])).Count; i++)
{
tc = new TableCell();
Label example = new Label();
example.Text = ((columnsResultFromSqlClients)(i)).ToString();
tc.Controls.Add(example);
tr.Cells.Add(tc);
}
tb1.Rows.Add(tr);
//filling the table
for (int i = 0; i < result.Count; i++)
{
tr = new TableRow();
tc = new TableCell();
//adding radio button
RadioButton RB = new RadioButton();
RB.Attributes.Add("value", ((ArrayList)(result[i]))[0].ToString());
RB.GroupName = "for_selecting";
RB.ID = ((ArrayList)(result[i]))[0].ToString();
RB.CheckedChanged += new EventHandler(RB_CheckedChanged2);
//RB.AutoPostBack = true;
RB.Attributes.Add("AutoPostBack", "True");
tc.Controls.Add(RB);
tr.Cells.Add(tc);
//adding content
for (int j = 0; j < ((ArrayList)(result[i])).Count; j++)
{
tc = new TableCell();
Label example = new Label();
example.Text = ((ArrayList)(result[i]))[j].ToString();
tc.Controls.Add(example);
tr.Cells.Add(tc);
}
tb1.Rows.Add(tr);
}
If I use RB.AutoPostBack = true;, I have no time to press the button to submit my choice, cause the page will reload when i click the one of the Radio Buttons.
Also the RB_CheckedChanged2 code:
protected void RB_CheckedChanged2(object sender, EventArgs e)
{
RadioButton tempRB = (RadioButton)sender;
if (tempRB.Checked)
{
selected_id = tempRB.ID;
}
}
The select_id is a static int varible with standart value = "-1".
If I am not mistaken, with dynamic controls in ASP.Net, you need to "rewire" their events on a postback. Remember that on a postback, dynamic controls are no longer there. You have to recreate them.
Related
I have a asp:panel that on a button click, I add some number of checkboxes to dynamically.
On another button click, I need to look at these checkboxes and check if they are checked.
I can't find the controls. I've tried doing FindControl with the ID that I've supplied it, as well as the ClientID.
The markup with the panel that the checkboxes get placed into, and the two buttons:
<asp:Panel runat="server" ScrollBars="Vertical" ID="pnlEmailCheckboxes" Height="150">
<br/>
<asp:CheckBox runat="server" Text="Other" ID="cbOtherEmail"/>
<asp:TextBox ID="txtOtherEmail" runat="server" Style="width: 270px;" CssClass="textbox-default"></asp:TextBox>
<br/>
</asp:Panel>
<asp:LinkButton ID="btnSendEmail" Text="<span>Send Email</span>" runat="server" CssClass="page-footer-button-highlight" OnClick="btnSendEmail_Click"></asp:LinkButton>
<asp:LinkButton ID="btnCloseEmail" Text="<span>Close</span>" runat="server" CssClass="page-footer-button" CausesValidation="false" OnClick="btnCloseEmail_OnClick"></asp:LinkButton>
The event that generates the textboxes:
protected void btnEmail_Click(object sender, EventArgs e)
{
List<CheckBox> cbList = new List<CheckBox>();
for (int i = 0; i < 10; i++)
{
CheckBox cb = new CheckBox();
cb.Text = "text" + i;
cb.ID = Guid.newGuid().ToString();
cb.ClientIDMode = ClientIDMode.Static;
pnlEmailCheckboxes.Controls.AddAt(0, cb);
pnlEmailCheckboxes.Controls.AddAt(0, new LiteralControl("<br/>"));
cbList.Add(cb);
}
Session["checkboxes"] = cbList;
mpeEmail.Show();
}
The button that tries to retrieve the textboxes (does not work):
protected void btnSendEmail_Click(object sender, EventArgs e)
{
//the email recipients
List<string> emailRecipients = new List<string>();
List<CheckBox> cbList = (List<CheckBox>)Session["checkboxes"];
foreach (CheckBox cb in cbList)
{
CheckBox cbClient = (CheckBox) pnlEmailCheckboxes.FindControl(cb.ClientID); //I've also tried to find it by cb.ID
//null reference here, the checkbox cbClient was not found
if (cbClient.Checked) emailRecipients.Add(cb.Text.Trim());
}
//Ive also tried this, it does not contain the dynamically generated checkboxes
//var cbControls = pnlEmailCheckboxes.Controls.OfType<CheckBox>();
}
Edit:
The client side html even shows the with the correct ID that matches the ID I'm searching for.
<input id="00e3a485-2083-4ef8-810b-6ed4fb1f62f9" type="checkbox" name="ctl00$Body$00e3a485-2083-4ef8-810b-6ed4fb1f62f9">
Try adding a unique ID to each dynamic control and setting the ClientIDMode = ClientIDMode.Static:
List<CheckBox> cbList = new List<CheckBox>();
for (int i = 0; i < 10; i++)
{
CheckBox cb = new CheckBox();
cb.ID = "DynamicCb" + i";
cb.ClientIDMode = ClientIDMode.Static;
cb.Text = "text" + i;
pnlEmailCheckboxes.Controls.AddAt(0, cb);
pnlEmailCheckboxes.Controls.AddAt(0, new LiteralControl("<br/>"));
cbList.Add(cb);
}
I've found a solution for my problem. If I add the controls in the OnInit method, I can see the checkboxes in the button click later on.
protected override void OnInit(EventArgs e)
{
List<CheckBox> cbList = new List<CheckBox>();
for (int i = 0; i < 10; i++)
{
CheckBox cb = new CheckBox();
cb.Text = "text" + i;
cb.ID = Guid.newGuid().ToString();
pnlEmailCheckboxes.Controls.AddAt(0, cb);
pnlEmailCheckboxes.Controls.AddAt(0, new LiteralControl("<br/>"));
cbList.Add(cb);
}
Session["checkboxes"] = cbList;
}
Another problem is present now, each checkbox always has Checked==False even when they are Checked on the UI. However, this is cause for another question.
My question i asked for "Randomly" adding controls in spefic
Table Cells. e.g.
if i call funtion CreateTable() , it should create tables
with vary number of rows and columns, and then for example if i
want a text box in Cell(0,1), a dropdown in cell(2,1) then again a text
area control in Cell(5,1) etc etc.( u getting my point, i am not
putting one type of control), how can i code that.The control state should be saved in the table.And whenever i open particylar webform it show shos all the control which i have created before
private void CreateTable(short noOfRows)
{
PlaceHolder p1 = new PlaceHolder();
Table table1 = new Table();
table1.BorderWidth = 1;
table1.BorderStyle = BorderStyle.Solid;
TableRow[] rows = new TableRow[noOfRows];
for (int i = 0; i < rows.Length; i++)
{
rows[i] = new TableRow();
}
table1.Rows.AddRange(rows);
TextBox t1 = new TextBox();
t1.Text = "Hello";
t1.EnableViewState = true;
TextBox t2 = new TextBox();
t2.Text = "World";
t2.EnableViewState = true;
Button btnOk = new Button();
btnOk.EnableViewState = true;
btnOk.Text = "OK";
Button btnCancel = new Button();
btnCancel.EnableViewState = true;
btnCancel.Text = "Cancel";
TableCell cell1=new TableCell();
TableCell cell2 = new TableCell();
TableCell cell3 = new TableCell();
TableCell cell4 = new TableCell();
cell1.Controls.Add(t1);
cell2.Controls.Add(t2);
cell3.Controls.Add(btnOk);
cell4.Controls.Add(btnCancel);
table1.Rows[0].Cells.AddAt(0, cell1);
table1.Rows[0].Cells.AddAt(1, cell2);
table1.Rows[1].Cells.AddAt(0, cell3);
table1.Rows[1].Cells.AddAt(1, cell4);
p1.Controls.Add(table1);
form1.Controls.Add(p1);
}
I am creating a web application that requires controls to be created dynamically on the click of a button, and then add the controls to an already constructed asp:table.
The problem is that the events for the dynamic controls do not fire (ciDD_SelectedIndexChanged).
In order: the button is clicked, it sets a Session variable for the control IDs, creates the controls, then adds them to the table row. This is done OnClick, and OnInit for post back.
Is there an easy way to set the event for the dynamic controls, or am I going about this in a horrible way?
The button and it's event:
<asp:ImageButton ID="addHardware" runat="server" ImageUrl="~/Images/plus.png" Height="24" Width="24" OnClick="addHardware_Click" ImageAlign="AbsMiddle" style="margin-left:7px" Visible="false" />
protected void addHardware_Click(object sender, ImageClickEventArgs e)
{
Session["rowCount"] = (Convert.ToInt32(Session["rowCount"]) + 1);
CreateControls(Convert.ToInt32(Session["rowCount"]));
CreateRow(Convert.ToInt32(Session["rowCount"]));
}
The Control creation function and the list they are saved to:
private static List<Control> _controls = new List<Control>();
private static List<Control> HWControls
{
get { return _controls; }
}
protected void CreateControls(int i)
{
DropDownList ci = new DropDownList();
ci.AutoPostBack = true;
ci.ID = "ciDD" + i;
ci.SelectedIndexChanged += new EventHandler(this.ciDD_SelectedIndexChanged);
ci.Items.Add(new ListItem("", ""));
ci.Items.Add(new ListItem("test1", "test1"));
ci.Items.Add(new ListItem("test2", "test2"));
DropDownList dt = new DropDownList();
dt.ID = "deviceTypeDD" + i;
DropDownList m = new DropDownList();
m.ID = "modelDD" + i;
TextBox qt = new TextBox();
qt.ID = "qtTB" + i;
DropDownList dv = new DropDownList();
dv.ID = "deviceNumDD" + i;
TextBox sn = new TextBox();
sn.ID = "serialTB" + i;
HWControls.Add(ci);
HWControls.Add(dt);
HWControls.Add(m);
HWControls.Add(qt);
HWControls.Add(dv);
HWControls.Add(sn);
}
The Row creation function, and it's corresponding List:
private static List<TableRow> _rows = new List<TableRow>();
private static List<TableRow> Rows
{
get { return _rows; }
}
protected void CreateRow(int i)
{
TableRow row = new TableRow();
TableCell cell = new TableCell();
TableCell cell1 = new TableCell();
TableCell cell2 = new TableCell();
TableCell cell3 = new TableCell();
TableCell cell4 = new TableCell();
TableCell cell5 = new TableCell();
cell.Controls.Add(HWControls.Find(x => x.ID.Contains("ciDD" + i)));
cell1.Controls.Add(HWControls.Find(x => x.ID.Contains("deviceTypeDD" + i)));
cell2.Controls.Add(HWControls.Find(x => x.ID.Contains("modelDD" + i)));
cell3.Controls.Add(HWControls.Find(x => x.ID.Contains("qtTB" + i)));
cell4.Controls.Add(HWControls.Find(x => x.ID.Contains("deviceNumDD" + i)));
cell5.Controls.Add(HWControls.Find(x => x.ID.Contains("serialTB" + i)));
row.Cells.Add(cell);
row.Cells.Add(cell1);
row.Cells.Add(cell2);
row.Cells.Add(cell3);
row.Cells.Add(cell4);
row.Cells.Add(cell5);
Rows.Add(row);
hardwareTable.Rows.Add(row);
}
The OnInit to recreate the controls/rows after post back:
protected override void OnInit(EventArgs e)
{
int i = Convert.ToInt32(Session["rowCount"]);
if (i != 0)
{
for (int j = 1; j <= i; j++)
{
CreateControls(j);
CreateRow(j);
}
}
base.OnInit(e);
}
I found that creating the eventhandlers in the PreInit phase solved the issue.
protected void Page_PreInit(object sender, EventArgs e)
{
foreach (Control c in HWControls)
{
if(c.ID.Contains("ciDD"))
{
((DropDownList)c).SelectedIndexChanged += new EventHandler(this.ciDD_SelectedIndexChanged);
}
else if (c.ID.Contains("deviceTypeDD"))
{
((DropDownList)c).SelectedIndexChanged += new EventHandler(this.deviceTypeDD_SelectedIndexChanged);
}
}
}
I have an asp.net web page that contain panel that will filled up on run time
protected void Page_Load(object sender, EventArgs e)
{
buildStructure(1);
}
and this is the method
public void buildStructure(int level_id)
{
pMain.Controls.Clear();
//Response.Write(#"<script language='javascript'>alert('" + level_id + "');</script>");
DataUtility DU = new DataUtility(#"****");
DataTable dt = DU.GetDataTable("SELECT * FROM dbo.PRStructure_Main WHERE level_id = "+level_id);
int curr_level = 1;
int curr_child = 1;
int totalchild = 0;
if (dt.Rows.Count > 0)
{
Panel pLevel = new Panel();
pLevel.CssClass = "level";
Panel pItem = new Panel();
pItem.CssClass = "item-ceo";
Label lItem = new Label();
lItem.Text = dt.Rows[0].ItemArray[2].ToString();
pItem.Controls.Add(lItem);
pLevel.Controls.Add(pItem);
pMain.Controls.Add(pLevel);
Panel pLevelLine = new Panel();
pLevelLine.CssClass = "level";
Panel pItemLine = new Panel();
pItemLine.CssClass = "item-line-ceo";
Panel pLine = new Panel();
pLine.CssClass = "horizontal-line";
pItemLine.Controls.Add(pLine);
pLevelLine.Controls.Add(pItemLine);
pMain.Controls.Add(pLevelLine);
Panel pLevelLine2 = new Panel();
pLevelLine2.CssClass = "level";
Panel pLevel2 = new Panel();
pLevel2.CssClass = "level";
dt = DU.GetDataTable("SELECT * FROM dbo.PRStructure_Main WHERE level_parent = "+(Convert.ToInt32( dt.Rows[0].ItemArray[0].ToString())));
lbItem2 = new LinkButton[dt.Rows.Count];
for (int i = 0; i < dt.Rows.Count; i++)
{
Panel pItemLine2 = new Panel();
Panel pLine2 = new Panel();
if (i == 0)
{
pItemLine2.CssClass = "item-line-level2-first";
pLine2.CssClass = "horizontal-line2-first";
}
else if (i == dt.Rows.Count - 1)
{
pItemLine2.CssClass = "item-line-level2-last";
pLine2.CssClass = "horizontal-line2-last";
}
else
{
pItemLine2.CssClass = "item-line-level2-middle";
pLine2.CssClass = "horizontal-line2-middle";
}
pItemLine2.Controls.Add(pLine2);
pLevelLine2.Controls.Add(pItemLine2);
Panel pItem2 = new Panel();
pItem2.CssClass = "item-level2";
Panel pItemContent2 = new Panel();
pItemContent2.CssClass = "item-level2-content";
lbItem2[i] = new LinkButton();
lbItem2[i].Text = dt.Rows[i].ItemArray[2].ToString();
int current_level1 = (int)dt.Rows[i].ItemArray[0];
//lbItem2.OnClientClick = "alert('" + current_level1 + "')";
//lbItem2.Click += new EventHandler((s,e) => evHandler(s,e, current_level1));
lbItem2[i].Click += new System.EventHandler(delegate(Object o, EventArgs a)
{
evHandler(o, a, current_level1);
});
pItemContent2.Controls.Add(lbItem2[i]);
//pLevel.Controls.Add(lbItem);
DataTable dt2 = DU.GetDataTable("SELECT * FROM dbo.PRStructure_Main WHERE level_parent = " + dt.Rows[i].ItemArray[0]);
Panel pMenuLevel = new Panel();
pMenuLevel.CssClass = "menu-level2";
//<div class="menu-level2-items">Assets Integrity Management</div>
for (int j = 0; j < dt2.Rows.Count; j++)
{
Panel pMenuLevelItems = new Panel();
pMenuLevelItems.CssClass = "menu-level2-items";
LinkButton lbMenuItem = new LinkButton();
lbMenuItem.Text = dt2.Rows[j].ItemArray[2].ToString();
int current_level2 = (int)dt2.Rows[j].ItemArray[0];
//lbMenuItem.Click += new EventHandler(delegate (Object o, EventArgs ee) { evHandler(s, ee,current_level2)});
lbMenuItem.Click += new EventHandler(delegate (Object o, EventArgs a)
{
evHandler(o, a, current_level2);
});
pMenuLevelItems.Controls.Add(lbMenuItem);
DataTable dt3 = DU.GetDataTable("SELECT * FROM dbo.PRStructure_Main WHERE level_parent = " + dt2.Rows[j].ItemArray[0]);
Panel pSubMenuLevel = new Panel();
pSubMenuLevel.CssClass = "sub-menu-level2";
// <div class="sub-menu-level2-items"> Business Application Section </div>
for (int k = 0; k < dt3.Rows.Count; k++)
{
Panel pSubMenuLevelItems = new Panel();
pSubMenuLevelItems.CssClass = "menu-level2-items";
LinkButton lbSubMenuItem = new LinkButton();
lbSubMenuItem.Text = dt3.Rows[k].ItemArray[2].ToString();
int current_level3 = (int)dt3.Rows[k].ItemArray[0];
lbMenuItem.Click += new EventHandler((s, e) => evHandler(s, e, current_level3));
pSubMenuLevelItems.Controls.Add(lbSubMenuItem);
pSubMenuLevel.Controls.Add(pSubMenuLevelItems);
}
pMenuLevelItems.Controls.Add(pSubMenuLevel);
pMenuLevel.Controls.Add(pMenuLevelItems);
}
pItemContent2.Controls.Add(pMenuLevel);
pItem2.Controls.Add(pItemContent2);
pLevel2.Controls.Add(pItem2);
}
pMain.Controls.Add(pLevelLine2);
pMain.Controls.Add(pLevel2);
}
}
I have a problem in this section
lbMenuItem.Click += new EventHandler((s, e) => evHandler(s, e, current_level3));
and this is the handler method
public void evHandler(Object s,EventArgs e, int someData){
//Response.Write(#"<script language='javascript'>alert('" + someData + "');</script>");
ScriptManager.RegisterStartupScript(this.Page, this.Page.GetType(),"err_msg","alert('" + someData + "');",
true);
buildStructure(someData);
}
it work properly first time
but when i click it again its make page load.
I think your page_load should be like below
protected void Page_Load(object sender, EventArgs e)
{
if(!IsPostBack){
buildStructure(1);
}
}
You need to recreate the exact same controls when posting back. If the page loads with only one control how will it know to raise the click event for a control that doesn't exists.
Edit:
From what I understand about asp.net page life cycle, you must have the controls created before post back data is restored, that's how page control events fire. So if you have a control say LinkButtonA which was dynamically created on the page and you click on it, for the click event to trigger on the server during the post back, it must be recreated before post back data is restored, therefore try Recreating dynamic controls in Page_Init instead of Page_Load and try to keep the input to your method "buildStructure" the same. Say if you have called it from the event handler with buildStructure("fifth_level") make sure that Page_Init does the same buildStructure("fifth_level").
Microsoft recommends to create the dynamic controls on preint so you need to create the same controls on preinit like this
http://msdn.microsoft.com/en-us/library/ms178472.aspx
protected override void OnPreInit(EventArgs e)
{
}
I am populating dynamic controls inside the update panel. The steps are
Step 1: Dynamic controls are populated inside dynamic table like this which is inside panel
<asp:Panel ID="pnlShowDDF" runat="server" Visible="False" ViewStateMode="Enabled">
</asp:Panel>
Step 2:
protected void loadTable()
{
HtmlTable tblDDF = new HtmlTable();
var objDDF = new ddf();
var dsDdfDetail = "DataSet Loaded"
if (dsDdfDetail.Tables[0].Rows.Count > 0)
{
int RowsCount = dsDdfDetail.Tables[0].Rows.Count;
for (int i = 0; i < RowsCount; i++)
{
HtmlTableRow tblNewRow = new HtmlTableRow();
HtmlTableCell tblDdfCell = new HtmlTableCell();
tblDdfCell1.Controls.Add(addCheckbox(dsDdfDetail.Tables[0].Rows[i][0].ToString()));
//The addCheckbox function returns the checkbox with its text
tblNewRow.Controls.Add(tblDdfCell);
tblDDF.Controls.Add(tblNewRow);
}
HtmlTableRow htFooterRow = new HtmlTableRow();
HtmlTableCell htFooterCell = new HtmlTableCell();
htFooterCell.Controls.Add(DelButton());
//DelButton() is written in below
htFooterCell.Attributes.Add("class", "pnlFooterRow");
htFooterCell.ColSpan = 2;
htFooterRow.Cells.Add(htFooterCell);
tblDDF.Controls.Add(htFooterRow);
}
pnlShowDDF.Controls.Add(tblDDF);
pnlShowDDF.Visible = true;
}
protected Button DelButton()
{
var btnDelete = new Button();
btnDelete.ID = "btnDelete";
btnDelete.Text = "De-Allocate";
btnDelete.Click += new EventHandler(btnDelete_Click);
btnDelete.Attributes.Add("class", "button");
btnDelete.ViewStateMode = ViewStateMode.Enabled;
return btnDelete;
}
Step 3 Need to access dynamic checkbox id from the btnDelete
void btnDelete_Click(object sender, EventArgs e)
{
//Need to access the checkbox id's here
foreach(Control chk in pnlShowDDF.Controls)
{
if(chk is CheckBox)
{
CheckBox chkbx= chk as CheckBox;
if(chkbx.Checked)
{
//Here i need to access the id's which i can't right now
}
}
}
}
Step 4: i have recalled the loadTable function on OnInit but no gains
protected override void OnInit(EventArgs e)
{
base.OnInit(e);
loadTable();
}
What should be done so that i can access the checkbox id's ??
Whenever you add dynamic controls, you have to add them in Page_Init event and assign them proper IDs, so that when a postback occurs, those dynamic added controls are created again along with their values and will be accessible in other events, in your case btnDelete_Click.
So what you are missing is assigning IDs to the table cells and rows, I hope you are assigning ID to the checkboxes.
========================= EDIT ============================
Here is the code that is working with me, btnDelete_Click has good enough changes in it. I am getting the checkboxes that I added in and if I check any of them, i get the value as true.
protected void loadTable()
{
HtmlTable tblDDF = new HtmlTable();
//var objDDF = new ddf();
//DataSet dsDdfDetail = new DataSet();
//if (dsDdfDetail.Tables[0].Rows.Count > 0)
//{
//int RowsCount = dsDdfDetail.Tables[0].Rows.Count;
for (int i = 0; i < 5; i++)
{
HtmlTableRow tblNewRow = new HtmlTableRow();
HtmlTableCell tblDdfCell = new HtmlTableCell();
tblDdfCell.Controls.Add(addCheckbox(i.ToString()));
//The addCheckbox function returns the checkbox with its text
tblNewRow.Controls.Add(tblDdfCell);
tblDDF.Controls.Add(tblNewRow);
}
HtmlTableRow htFooterRow = new HtmlTableRow();
HtmlTableCell htFooterCell = new HtmlTableCell();
htFooterCell.Controls.Add(DelButton());
//DelButton() is written in below
htFooterCell.Attributes.Add("class", "pnlFooterRow");
htFooterCell.ColSpan = 2;
htFooterRow.Cells.Add(htFooterCell);
tblDDF.Controls.Add(htFooterRow);
//}
pnlShowDDF.Controls.Add(tblDDF);
pnlShowDDF.Visible = true;
}
protected Button DelButton()
{
var btnDelete = new Button();
btnDelete.ID = "btnDelete";
btnDelete.Text = "De-Allocate";
btnDelete.Click += new EventHandler(btnDelete_Click);
btnDelete.Attributes.Add("class", "button");
//btnDelete.ViewStateMode = ViewStateMode.Enabled;
return btnDelete;
}
protected CheckBox addCheckbox(string id)
{
CheckBox chk = new CheckBox();
chk.ID = id;
return chk;
}
void btnDelete_Click(object sender, EventArgs e)
{
//Need to access the checkbox id's here
foreach (Control chk in pnlShowDDF.Controls)
{
if (chk is HtmlTable)
{
HtmlTable tbl = (HtmlTable)chk;
foreach (HtmlTableRow row in tbl.Rows)
{
foreach (HtmlTableCell cell in row.Cells)
{
foreach (Control chk1 in cell.Controls)
{
if (chk1 is CheckBox)
{
CheckBox chkbx = chk1 as CheckBox;
if (chkbx.Checked)
{
//Here i need to access the id's which i can't right now
}
}
}
}
}
}
}
}