 |
| ASP.NET 3.5 Basics If you are new to ASP or ASP.NET programming with version 3.5, this is the forum to begin asking questions. Please also see the Visual Web Developer 2008 forum. |
Welcome to the p2p.wrox.com Forums.
You are currently viewing the ASP.NET 3.5 Basics section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
|
|
|
|

March 12th, 2010, 02:28 AM
|
|
Authorized User
|
|
Join Date: Mar 2010
Posts: 65
Thanks: 6
Thanked 0 Times in 0 Posts
|
|
Problem with Dynamical Controls
Hi,
I am using Table class in page load event to display my records from database.
I have buttton Control in my Design mode. I just want to add this controls to the Table Cell in my Table Class in page_load event for every single record it displays from database.
say if database displays 5 records, then i want 5 instances of this single button in each record.
The result is: i am getting this Button only in the last record it is displaying.
I am adding this control using the button ID.Iam working on this for a long time. Could somebody help?
|
|

March 12th, 2010, 07:08 AM
|
|
Authorized User
|
|
Join Date: Sep 2009
Posts: 12
Thanks: 1
Thanked 0 Times in 0 Posts
|
|
Adding Controls to Table Cells
You need create a table cell first. Then store the button control in the table cell. Then add the cell to each new table row.
|
|

March 12th, 2010, 06:47 PM
|
|
Authorized User
|
|
Join Date: Mar 2010
Posts: 65
Thanks: 6
Thanked 0 Times in 0 Posts
|
|
Yes thats how i have added Custom control inside the cell within a loop. So that every time it display a record from database , i want that custom control to be shown in each record.
But iam getting only in a final record.
I think since i have only one Custom Button control which has a single ID. It is displaying only once. I want the instances of that control to display in all the records.
My code is like this:
After i set the connection string,
while (reader.Read())
{
-----
-----
TableRow comm = new TableRow();
TableHeaderCell commvote = new TableHeaderCell();
commvote.Controls.Add(btnInfo);(btnInfo is the button control which i created in the design mode. It is getting added in the final record but not in the first few records.)
}
So I am very confused.
|
|

March 13th, 2010, 07:19 AM
|
 |
Wrox Author
|
|
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
|
|
Hi there,
When you do this:
Code:
commvote.Controls.Add(btnInfo);
you *move* the Button from its previous location to the Controls collection of the current commvote. In other words, you can't have the same Button show up in multiple places. Instead, inside the loop you need to instantiate a new Button every time:
Code:
Button btnInfo = new Button();
... do what you need to do with btnInfo here, like settings its ID
commvote.Controls.Add(btnInfo);
Hope this helps,
Imar
|
|

March 15th, 2010, 05:04 PM
|
|
Authorized User
|
|
Join Date: Mar 2010
Posts: 65
Thanks: 6
Thanked 0 Times in 0 Posts
|
|
Dynamic Controls Problems
Thanks you so much. I also tried what you suggested me. It worked, Buttons are added for all the records, but the function I specified inside the Button is not working.
I am trying to add a Panel which contain some data from Database to be displayed when the Mouse Hover on the Dynamic Button i added. I could see only the Button. But when i hover on it or when i click it, it wasn't working. please help.
My codeings are like this:
while ()
{
------------
------------
----------
Button but1 = new Button();
but1.Text = "Hover button";
Panel pan1 = new Panel();
Label lab = new Label();
lab.Text = "Empty Panel";
pan1.Controls.Add(lab);
AjaxControlToolkit.HoverMenuExtender hov= new AjaxControlToolkit.HoverMenuExtender();
hov.TargetControlID = "but1";
hov.PopupControlID = "pan1";
commvote.Controls.Add(lnkbut);
-------
}
|
|

March 15th, 2010, 05:17 PM
|
 |
Wrox Author
|
|
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
|
|
This is all very unclear. What error? When? In the browser or at compile / development / runtime? And what is lnkbut? And what is commvote? And why are you instantiating hov but then never use it?
In other words: please be more specific. Supplied relevant code, a detailed description of the situation and clear error messages. Otherwise, we won't be able to help you out.
Cheers,
Imar
|
|

March 16th, 2010, 12:01 AM
|
|
Authorized User
|
|
Join Date: Mar 2010
Posts: 65
Thanks: 6
Thanked 0 Times in 0 Posts
|
|
Sorry about that. I was unclear.
After the connection string has been set, I dynamically wants to display records using Table Class inside this loop. Where i want to display the dynamically created button 'but1' in each record from Database.
'hov' is the Ajax Hover menu extender which i want to display a panel contains some information say 'label', when i hover on the dynamic button 'but1' .
I am not getting any Error Messages. I am getting the dynamically created Button in each records inside the Table. But when i hover on it, it is not displaying a Panel which i created using Hovermenu extender.
Coding is:
while (Reader.read())
{
TableRow ---
TableHeaderCell commvote = new TableHeaderCell();
Button but1 = new Button(); //(This is the button i want to display in each Record from database).
but1.Text = "Hover button";
AjaxControlToolkit.HoverMenuExtender hov= new AjaxControlToolkit.HoverMenuExtender();
Panel pan1 = new Panel();
Label lab = new Label();
lab.Text = "Empty Panel";
pan1.Controls.Add(lab);
hov.TargetControlID = "but1";
hov.PopupControlID = "pan1";
commvote.Controls.Add(but1);
}
Also I tried this using LinkButton Control i dynamically created instead of a Button Control. Its not working for that either.
Last edited by Gayathri79; March 16th, 2010 at 12:07 AM..
|
|

March 16th, 2010, 09:57 AM
|
 |
Wrox Author
|
|
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
|
|
Hi there,
It's still not very clear, but it looks to me you're not adding all the necessary controls. For example, you only add the button but you don't had the hov control...
Cheers,
Imar
|
|

March 16th, 2010, 12:38 PM
|
|
Authorized User
|
|
Join Date: Mar 2010
Posts: 65
Thanks: 6
Thanked 0 Times in 0 Posts
|
|
Sorry i dont really know how to add the 'hov' control. I thought i did it by using the code:
AjaxControlToolkit.HoverMenuExtender hov= new AjaxControlToolkit.HoverMenuExtender();
Because when i tried this using custom control from Tool box, it worked. But cannot do it dynamically.
So is that the Issue?
Thanks
Gayathri
|
|

March 16th, 2010, 01:17 PM
|
 |
Wrox Author
|
|
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
|
|
Nope, that doesn't add the control. It just instantiates it in memory. It will be gone as soon as the method is done.
You need to add it to a container control like commvote, just as you're doing with the button using the Add method. That way it gets sent to the browser, just as the button....
Hope this helps,
Imar
|
|
 |