Wrox Programmer Forums
|
ASP.NET 1.0 and 1.1 Professional For advanced ASP.NET 1.x coders. Beginning-level questions will be redirected to other forums. NOT for "classic" ASP 3 or the newer ASP.NET 2.0 and 3.5
Welcome to the p2p.wrox.com Forums.

You are currently viewing the ASP.NET 1.0 and 1.1 Professional 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
 
Old April 9th, 2007, 07:37 AM
Authorized User
 
Join Date: Mar 2007
Posts: 18
Thanks: 0
Thanked 0 Times in 0 Posts
Default create buttons dynamically on webpage

hello friends!
i want to creat buttons dynamically on webpage....
i have done it with placeholder and i got the button on webpage but they appears on the left corner of page i.e. at starting of page..
i want that buttons in middle of the page...or at any specific location defined by me....
how can i do this???
please help me out.....
bye....have a nice day....

 
Old April 9th, 2007, 07:47 AM
Wrox Author
 
Join Date: Oct 2005
Posts: 4,104
Thanks: 1
Thanked 64 Times in 64 Posts
Send a message via AIM to dparsons
Default

This depends on how your web page is set up. Personally I place my dynamice controls in some sort of a container (normally a panel) so I know where at on the page the buttons will render. If you are using a grid layout for your webform you can use a style to position the buttons on your page, however, I think you will find this cumbersome.

Code that adds dynamic controls to a container:
for(int i=0;i<5;i++)
{
  Button btn = new Button;
  btn.ID = i.ToString();
  btn.Click += new System.EventHandler(this.btnClickEventHandler);
  panel1.Controls.Add(btn);
}

hth.

================================================== =========
Read this if you want to know how to get a correct reply for your question:
http://www.catb.org/~esr/faqs/smart-questions.html
^^Took that from planoie's profile^^
^^Modified text taken from gbianchi profile^^
================================================== =========
Technical Editor for: Professional Search Engine Optimization with ASP.NET
http://www.wiley.com/WileyCDA/WileyT...470131470.html
================================================== =========
Why can't Programmers, program??
http://www.codinghorror.com/blog/archives/000781.html
================================================== =========
 
Old April 10th, 2007, 06:25 AM
Authorized User
 
Join Date: Mar 2007
Posts: 18
Thanks: 0
Thanked 0 Times in 0 Posts
Default

thank you for your answer...

now i want to use the click event of that dynamically created button..can i do this??
if yes then plz give me code sample for the same....

bye.....

 
Old April 10th, 2007, 06:42 AM
Wrox Author
 
Join Date: Oct 2005
Posts: 4,104
Thanks: 1
Thanked 64 Times in 64 Posts
Send a message via AIM to dparsons
Default

Thats what this line does:
btn.Click += new System.EventHandler(this.btnClickEventHandler);

It attaches an event handler to the dynamic buttons click event (This is the same as doing AddHandler btn.Click, AddressOf btnClickEventHandler in VB) just make sure that the method that you wire to the buttons click event accepts the correct arguments or you will get a compiler error.

================================================== =========
Read this if you want to know how to get a correct reply for your question:
http://www.catb.org/~esr/faqs/smart-questions.html
^^Took that from planoie's profile^^
^^Modified text taken from gbianchi profile^^
================================================== =========
Technical Editor for: Professional Search Engine Optimization with ASP.NET
http://www.wiley.com/WileyCDA/WileyT...470131470.html
================================================== =========
Why can't Programmers, program??
http://www.codinghorror.com/blog/archives/000781.html
================================================== =========
 
Old April 19th, 2007, 04:16 PM
Registered User
 
Join Date: Apr 2007
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Default

I am also doing this (in VB.net however) and now would like to individually add different code behind each button. Right now, whichever button is clicked, it executes the same code.

 
Old April 19th, 2007, 05:20 PM
Wrox Author
 
Join Date: Oct 2005
Posts: 4,104
Thanks: 1
Thanked 64 Times in 64 Posts
Send a message via AIM to dparsons
Default

You will have to set up some logic, be it a Case statement or a complex if to have different event handles for dynamic buttons sooo:

For i = 0 to 5
Dim btn as new Button
btn.ID = "something"

SELECT Case i
Case 1
    Addhandler btn.click, AddressOf [method]
Case 1
    Addhandler btn.click, AddressOf [method 2]
[etc]
End Select
Next

HTH

================================================== =========
Read this if you want to know how to get a correct reply for your question:
http://www.catb.org/~esr/faqs/smart-questions.html
^^Took that from planoie's profile^^
^^Modified text taken from gbianchi profile^^
================================================== =========
Technical Editor for: Professional Search Engine Optimization with ASP.NET
http://www.wiley.com/WileyCDA/WileyT...470131470.html
================================================== =========
Why can't Programmers, program??
http://www.codinghorror.com/blog/archives/000781.html
================================================== =========





Similar Threads
Thread Thread Starter Forum Replies Last Post
Dynamically add buttons to dataGrid in a placehold siliconvalley ASP.NET 2.0 Basics 0 October 26th, 2006 06:23 AM
VBA to create PDF from webpage ncarty97 Excel VBA 0 September 25th, 2006 02:48 PM
Dynamically added panel with radio buttons ADM10 Visual Basic 2005 Basics 1 May 11th, 2006 10:27 PM
Problem with dynamically rendered radio buttons daddyunit Javascript 1 January 19th, 2006 04:41 AM
Dynamically create tables vickriz Javascript How-To 8 August 5th, 2003 03:00 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.