I am creating dynamic controls but not on page_load event but on one of the button click event.
I m able to get the controls value by using request.form but i m unable to handle the event created of dyanamically created button.
Please help me, if any one having solution for my problem.
I know that i can raise that event if i recreate these controls on page load but my reqirements doesn't allow me to do so.
My code for dynamially creating controls r as follows:
Expand|Select|Wrap|Line Numbers
- protected void generateAttributesForType()
- {
- oCatMgrBl.intListingTypeId =Convert.ToInt32(txtListingTypeId.Text.ToString());
- ht=oCatMgrBl.return_AttributesForListingType();
- if (ht["Status"].ToString() == "S")
- {
- if (((DataSet)ht["AttDataSet"]).Tables[0].Rows.Count > 0)
- {
- DataView dv= new DataView(((DataSet)ht["AttDataSet"]).Tables[1], "true", "", DataViewRowState.CurrentRows);
- foreach (DataRow dr in ((DataSet)ht["AttDataSet"]).Tables[0].Rows)
- {
- HtmlTableRow htr = new HtmlTableRow();
- HtmlTableCell htc11 = new HtmlTableCell();
- HtmlTableCell htc12 = new HtmlTableCell();
- HtmlTableCell htc13 = new HtmlTableCell();
- HtmlTableCell htc14 = new HtmlTableCell();
- HtmlTableCell htc15 = new HtmlTableCell();
- HtmlTableCell htc16 = new HtmlTableCell();
- HtmlTableCell htc17 = new HtmlTableCell();
- htc11.VAlign = "top";
- htc12.VAlign = "top";
- htc13.VAlign = "top";
- htc14.VAlign = "top";
- htc15.VAlign = "top";
- htc16.VAlign = "top";
- htc17.VAlign = "top";
- htr.ID = dr["intAttributeID"].ToString();
- htc11.Controls.Add(new LiteralControl(dr["vchAttributeName"].ToString()+":"));
- htc11.Align = "right";
- htc11.Attributes.Add("width", "29%");
- htr.Cells.Add(htc11);
- // To generate the control either textbox, dropdownlist
- if (dr["enumControlType"].ToString().Trim() == "T")
- {
- TextBox txt = new TextBox();
- txt.ID = "txt"+ dr["intAttributeID"].ToString();
- txt.CssClass = "input";
- htc12.Controls.Add(txt);
- htc12.Align = "left";
- htc12.Attributes.Add("width", "45%");
- htr.Cells.Add(htc12);
- }
- //for adding up buttons
- ImageButton imgUp = new ImageButton();
- imgUp.ID = "imgUp" + dr["intAttributeID"].ToString();
- imgUp.ImageUrl = "images/up.gif";
- imgUp.CommandArgument = dr["intTypeSequencingId"].ToString() + "," + dr["intAttributeID"].ToString();
- imgUp.Click += new ImageClickEventHandler(imgUp_Click);
- htc16.Controls.Add(imgUp);
- htc16.Align = "left";
- if (dr["intTypeSequencingId"].ToString() == ((DataSet)ht["AttDataSet"]).Tables[0].Compute("min(intTypeSequencingId)","").ToString())
- {
- imgUp.Attributes.Add("onclick", "javascript:alert('You are at top level');return false;");
- }
- htr.Cells.Add(htc16);
- //for adding Down buttons
- ImageButton imgDown = new ImageButton();
- imgDown.ID = "imgDown" + dr["intAttributeID"].ToString();
- imgDown.ImageUrl = "images/down.gif";
- imgDown.CommandArgument = dr["intTypeSequencingId"].ToString() + "," + dr["intAttributeID"].ToString();
- imgDown.Click += new ImageClickEventHandler(imgDown_Click);
- Page.Controls.Add(imgDown);
- htc17.Controls.Add(imgDown);
- htc17.Align = "left";
- if (dr["intTypeSequencingId"].ToString() == ((DataSet)ht["AttDataSet"]).Tables[0].Compute("max(intTypeSequencingId)", "").ToString())
- {
- imgDown.Attributes.Add("onclick", "javascript:alert('You are at bottom level');return false;");
- }
- htr.Cells.Add(htc17);
- Session["Table"] = 1;
- tblAttributes.Rows.Add(htr);
- }
- }
- }
- }
- void imgDown_Click(object sender, ImageClickEventArgs e)
- {
- ImageButton move = (ImageButton)sender;
- string[] abc = move.CommandArgument.ToString().Split(',');
- oCatMgrBl.intAttributeId = Convert.ToInt32(abc[1].ToString());
- oCatMgrBl.SequenceId = Convert.ToInt32(abc[0].ToString());
- oCatMgrBl.whereToMove = "D";
- ht=oCatMgrBl.UpdateListingSequencing();
- MessageControl1.showMessage(ht);
- //generateAttributesForType();
- }