Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > ASP.NET and ASP > ASP.NET 3.5 > ASP.NET 3.5 Basics
Password Reminder
Register
Register | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
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 tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developersí questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
 
 
Thread Tools Display Modes
  #1 (permalink)  
Old March 12th, 2010, 02:28 AM
Authorized User
 
Join Date: Mar 2010
Posts: 65
Thanks: 6
Thanked 0 Times in 0 Posts
Default 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?
  #2 (permalink)  
Old March 12th, 2010, 07:08 AM
Authorized User
 
Join Date: Sep 2009
Location: Everett, WA
Posts: 12
Thanks: 1
Thanked 0 Times in 0 Posts
Wink 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.
  #3 (permalink)  
Old March 12th, 2010, 06:47 PM
Authorized User
 
Join Date: Mar 2010
Posts: 65
Thanks: 6
Thanked 0 Times in 0 Posts
Default

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.
  #4 (permalink)  
Old March 13th, 2010, 07:19 AM
Imar's Avatar
Wrox Author
Points: 71,164, Level: 100
Points: 71,164, Level: 100 Points: 71,164, Level: 100 Points: 71,164, Level: 100
Activity: 100%
Activity: 100% Activity: 100% Activity: 100%
 
Join Date: Jun 2003
Location: Utrecht, Netherlands.
Posts: 16,960
Thanks: 79
Thanked 1,559 Times in 1,536 Posts
Default

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
__________________
Imar Spaanjaars
http://Imar.Spaanjaars.Com
Follow me on Twitter

Author of Beginning ASP.NET 4.5 : in C# and VB, Beginning ASP.NET Web Pages with WebMatrix
and Beginning ASP.NET 4 : in C# and VB.
Did this post help you? Click the button below this post to show your appreciation!
  #5 (permalink)  
Old March 15th, 2010, 06:04 PM
Authorized User
 
Join Date: Mar 2010
Posts: 65
Thanks: 6
Thanked 0 Times in 0 Posts
Default 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);
-------
}
  #6 (permalink)  
Old March 15th, 2010, 06:17 PM
Imar's Avatar
Wrox Author
Points: 71,164, Level: 100
Points: 71,164, Level: 100 Points: 71,164, Level: 100 Points: 71,164, Level: 100
Activity: 100%
Activity: 100% Activity: 100% Activity: 100%
 
Join Date: Jun 2003
Location: Utrecht, Netherlands.
Posts: 16,960
Thanks: 79
Thanked 1,559 Times in 1,536 Posts
Default

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
__________________
Imar Spaanjaars
http://Imar.Spaanjaars.Com
Follow me on Twitter

Author of Beginning ASP.NET 4.5 : in C# and VB, Beginning ASP.NET Web Pages with WebMatrix
and Beginning ASP.NET 4 : in C# and VB.
Did this post help you? Click the button below this post to show your appreciation!
  #7 (permalink)  
Old March 16th, 2010, 01:01 AM
Authorized User
 
Join Date: Mar 2010
Posts: 65
Thanks: 6
Thanked 0 Times in 0 Posts
Default

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 01:07 AM.
  #8 (permalink)  
Old March 16th, 2010, 10:57 AM
Imar's Avatar
Wrox Author
Points: 71,164, Level: 100
Points: 71,164, Level: 100 Points: 71,164, Level: 100 Points: 71,164, Level: 100
Activity: 100%
Activity: 100% Activity: 100% Activity: 100%
 
Join Date: Jun 2003
Location: Utrecht, Netherlands.
Posts: 16,960
Thanks: 79
Thanked 1,559 Times in 1,536 Posts
Default

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
__________________
Imar Spaanjaars
http://Imar.Spaanjaars.Com
Follow me on Twitter

Author of Beginning ASP.NET 4.5 : in C# and VB, Beginning ASP.NET Web Pages with WebMatrix
and Beginning ASP.NET 4 : in C# and VB.
Did this post help you? Click the button below this post to show your appreciation!
  #9 (permalink)  
Old March 16th, 2010, 01:38 PM
Authorized User
 
Join Date: Mar 2010
Posts: 65
Thanks: 6
Thanked 0 Times in 0 Posts
Default

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
  #10 (permalink)  
Old March 16th, 2010, 02:17 PM
Imar's Avatar
Wrox Author
Points: 71,164, Level: 100
Points: 71,164, Level: 100 Points: 71,164, Level: 100 Points: 71,164, Level: 100
Activity: 100%
Activity: 100% Activity: 100% Activity: 100%
 
Join Date: Jun 2003
Location: Utrecht, Netherlands.
Posts: 16,960
Thanks: 79
Thanked 1,559 Times in 1,536 Posts
Default

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
__________________
Imar Spaanjaars
http://Imar.Spaanjaars.Com
Follow me on Twitter

Author of Beginning ASP.NET 4.5 : in C# and VB, Beginning ASP.NET Web Pages with WebMatrix
and Beginning ASP.NET 4 : in C# and VB.
Did this post help you? Click the button below this post to show your appreciation!
 


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
Problem regarding Login controls bond007 ASP.NET 2.0 Basics 1 April 16th, 2009 02:14 AM
Problem with Try it Out List Controls phage BOOK: Beginning ASP.NET 3.5 : in C# and VB BOOK ISBN: 978-0-470-18759-3 6 September 15th, 2008 03:15 PM
Problem with user controls jamara ASP.NET 2.0 Basics 7 November 17th, 2006 05:34 PM
problem in user controls nishantmp1 ASP.NET 1.0 and 1.1 Basics 1 September 27th, 2006 10:43 AM
problem in using Image controls harini19 VB How-To 1 March 5th, 2004 02:34 PM



All times are GMT -4. The time now is 03:42 PM.


Powered by vBulletin®
Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.