473,466 Members | 1,314 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Event handling of dyanmic controls

9 New Member
Hi All,

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
  1. protected void generateAttributesForType()
  2. {
  3. oCatMgrBl.intListingTypeId =Convert.ToInt32(txtListingTypeId.Text.ToString());
  4. ht=oCatMgrBl.return_AttributesForListingType();
  5.  
  6. if (ht["Status"].ToString() == "S")
  7. {
  8. if (((DataSet)ht["AttDataSet"]).Tables[0].Rows.Count > 0)
  9. {
  10. DataView dv= new DataView(((DataSet)ht["AttDataSet"]).Tables[1], "true", "", DataViewRowState.CurrentRows);
  11. foreach (DataRow dr in ((DataSet)ht["AttDataSet"]).Tables[0].Rows)
  12. {
  13.  
  14. HtmlTableRow htr = new HtmlTableRow();
  15. HtmlTableCell htc11 = new HtmlTableCell();
  16. HtmlTableCell htc12 = new HtmlTableCell();
  17. HtmlTableCell htc13 = new HtmlTableCell();
  18. HtmlTableCell htc14 = new HtmlTableCell();
  19. HtmlTableCell htc15 = new HtmlTableCell();
  20. HtmlTableCell htc16 = new HtmlTableCell();
  21. HtmlTableCell htc17 = new HtmlTableCell();
  22. htc11.VAlign = "top";
  23. htc12.VAlign = "top";
  24. htc13.VAlign = "top";
  25. htc14.VAlign = "top";
  26. htc15.VAlign = "top";
  27. htc16.VAlign = "top";
  28. htc17.VAlign = "top";
  29. htr.ID = dr["intAttributeID"].ToString();
  30.  
  31. htc11.Controls.Add(new LiteralControl(dr["vchAttributeName"].ToString()+":"));
  32. htc11.Align = "right";
  33. htc11.Attributes.Add("width", "29%");
  34. htr.Cells.Add(htc11);
  35.  
  36. // To generate the control either textbox, dropdownlist
  37. if (dr["enumControlType"].ToString().Trim() == "T")
  38. {
  39. TextBox txt = new TextBox();
  40. txt.ID = "txt"+ dr["intAttributeID"].ToString();
  41. txt.CssClass = "input";
  42. htc12.Controls.Add(txt);
  43. htc12.Align = "left";
  44. htc12.Attributes.Add("width", "45%");
  45. htr.Cells.Add(htc12);
  46. }
  47.  
  48.  
  49.  
  50. //for adding up buttons
  51. ImageButton imgUp = new ImageButton();
  52. imgUp.ID = "imgUp" + dr["intAttributeID"].ToString();
  53. imgUp.ImageUrl = "images/up.gif";
  54. imgUp.CommandArgument = dr["intTypeSequencingId"].ToString() + "," + dr["intAttributeID"].ToString();
  55. imgUp.Click += new ImageClickEventHandler(imgUp_Click);
  56. htc16.Controls.Add(imgUp);
  57. htc16.Align = "left";
  58. if (dr["intTypeSequencingId"].ToString() == ((DataSet)ht["AttDataSet"]).Tables[0].Compute("min(intTypeSequencingId)","").ToString())
  59. {
  60. imgUp.Attributes.Add("onclick", "javascript:alert('You are at top level');return false;");
  61. }
  62. htr.Cells.Add(htc16);
  63.  
  64. //for adding Down buttons
  65. ImageButton imgDown = new ImageButton();
  66. imgDown.ID = "imgDown" + dr["intAttributeID"].ToString();
  67. imgDown.ImageUrl = "images/down.gif";
  68. imgDown.CommandArgument = dr["intTypeSequencingId"].ToString() + "," + dr["intAttributeID"].ToString();
  69. imgDown.Click += new ImageClickEventHandler(imgDown_Click);
  70. Page.Controls.Add(imgDown);
  71. htc17.Controls.Add(imgDown);
  72. htc17.Align = "left";
  73. if (dr["intTypeSequencingId"].ToString() == ((DataSet)ht["AttDataSet"]).Tables[0].Compute("max(intTypeSequencingId)", "").ToString())
  74. {
  75. imgDown.Attributes.Add("onclick", "javascript:alert('You are at bottom level');return false;");
  76. }
  77. htr.Cells.Add(htc17);
  78. Session["Table"] = 1;
  79. tblAttributes.Rows.Add(htr);
  80. }
  81.  
  82. }
  83.  
  84. }
  85.  
  86. }
  87.  
  88. void imgDown_Click(object sender, ImageClickEventArgs e)
  89. {
  90. ImageButton move = (ImageButton)sender;
  91. string[] abc = move.CommandArgument.ToString().Split(',');
  92. oCatMgrBl.intAttributeId = Convert.ToInt32(abc[1].ToString());
  93. oCatMgrBl.SequenceId = Convert.ToInt32(abc[0].ToString());
  94. oCatMgrBl.whereToMove = "D";
  95. ht=oCatMgrBl.UpdateListingSequencing();
  96. MessageControl1.showMessage(ht);
  97. //generateAttributesForType();
  98. }
Thanks.......
Apr 6 '07 #1
2 1331
kenobewan
4,871 Recognized Expert Specialist
What exactly are your requirements? I don't believe that you can do this in one function.
Apr 8 '07 #2
Hellogeetu
9 New Member
I m creating forms field from the table.
According to the category i selected the form fields also changes. So i couldn't create controls on page load i have to create it on dropdown selection changed event. Also i have to change the sequencing of the form attributes.

What exactly are your requirements? I don't believe that you can do this in one function.
Apr 9 '07 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

0
by: luca | last post by:
Hi all. My problem is that I can't handle events raised from child components within a composite server control when the control is created dynamically. Everything works fine if the same control...
6
by: Steve Caliendo | last post by:
Hi, I'm creating 5 ImageButton controls in the panel control, and I have a unique ID specified for each one. When I click on any one of them, the Page_Load executes (Of course), but how do I...
2
by: hn | last post by:
Hi, I have linkbuttons created dynamically and they display fine on the web page. However, when I click on the those link buttons, the event doesn't fire. Please tell me what's wrong with the...
5
by: Russell Smallwood | last post by:
Hello all, Why can't I wire up an event during the "Raise PostBackEvent" stage of a postback? Just in case this is the wrong question, the situation: deep in the bowls of some code-behind...
1
by: Adrian Parker | last post by:
At postback time, the controls are all recreated before an event fires. If the event determines that some of the controls need to be replaced with different controls that you can't create as...
7
by: Girish | last post by:
OK.. phew. Playing with data grids for the past few days has been fun and a huge learning experience.. My problem. I have a requirement to display a gird with a gird. Within the embedded grid,...
2
by: =?Utf-8?B?UGFkYW0=?= | last post by:
i have created couple of dynamic controls (dropdownlist and imagebutton) in webuser controls and assigned selected index change event and image button clicked. I am giving names to control...
2
by: John Kotuby | last post by:
Hi guys, I am converting a rather complicated database driven Web application from classic ASP to ASP.NET 2.0 using VB 2005 as the programming language. The original ASP application works quite...
1
by: raghulvarma | last post by:
I have created a custom control to get the values and sum them, Here I am able to get display the controls but I am not able to add the values in the text box which means that I am not able to catch...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
1
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.