Wrox Home  
Search P2P Archive for: Go

  Return to Index  

aspx thread: Placing a control dynamically onto a page...


Message #1 by "Al LeMay" <alemay@d...> on Tue, 20 Nov 2001 11:35:58 -0800
This is a multi-part message in MIME format.



------_=_NextPart_001_01C171FA.9442D498

Content-Type: text/plain;

	charset="US-ASCII"

Content-Transfer-Encoding: quoted-printable



All



I have a web form that has no controls on it. On page_load() it goes to

a database and retrieves a set of records. The records are then placed

onto Labels and RadioButtons, and then dynamically added to the page

through the Controls.Add() method.  Now here is the stickler, is there

any "easy way" to position the controls?



I am currently pondering writing the entire mess as HTML code to a

buffer.  Then reading the buffer to format the page.  But one problem, I

do not know how large to make the buffer. I could make it some arbitrary

length, but then I may over run it. Or not completely fill it, wasting

memory.



So are there any ideas out there on this?



Much appreciated.



Al LeMay

Virtuoso, Ltd.

Quality Assurance Manager

alemay@d...

tele:  (xxx) xxx-xxxx

cell:  (xxx) xxx-xxxx



http://www.virtuoso.com/



"Be joyful always; pray continually; give thanks in all circumstances."

- 1 Thessalonians 5:18






Message #2 by Jeri Lamy <jlamy@2...> on Tue, 20 Nov 2001 13:11:39 -0700
This message is in MIME format. Since your mail reader does not understand

this format, some or all of this message may not be legible.



------_=_NextPart_001_01C171FF.901E0450

Content-Type: text/plain;

	charset="ISO-8859-1"



By using the Style property of the controls, you can set a string that can

include positioning, like so:

 

protected System.Web.UI.WebControls.LinkButton Add;

Add.Style = "position:absolute; left:25px; top:10px";

 

You can put anything in the Style property just like you normally would with

a regular HTML or DHTML control.

 

There are, however, other issues you may want to consider when dynamically

creating controls through code.  For instance, anything created in code must

be created EVERY TIME you postback the page.  You cannot check the

IsPostback property in the Page_Load and only load them the first

time...they will disappear when you postback the page then.  In the IBuySpy

demo, they load the dynamic controls in the Page_Init function, and they are

loaded every time.  The other problem that this presents is, if you are

wanting to do a postback to SAVE data that may have been updated in your

dynamically created controls, this will not work...because the dynamic

controls are not persisted on postback.

 

If this doesn't present problems for what you are trying to do, you should

still create them in the Page_Init function.  If you create them in

Page_Load, any events that you want to hook to server controls will not be

wired.  At least, I couldn't get them to fire.

 

Jeri Lamy

Sr. Programmer



-----Original Message-----

From: Al LeMay [mailto:alemay@d...]

Sent: Tuesday, November 20, 2001 12:36 PM

To: ASP+

Subject: [aspx] Placing a control dynamically onto a page...







All 



I have a web form that has no controls on it. On page_load() it goes to a

database and retrieves a set of records. The records are then placed onto

Labels and RadioButtons, and then dynamically added to the page through the

Controls.Add() method.  Now here is the stickler, is there any "easy way" to

position the controls?



I am currently pondering writing the entire mess as HTML code to a buffer.

Then reading the buffer to format the page.  But one problem, I do not know

how large to make the buffer. I could make it some arbitrary length, but

then I may over run it. Or not completely fill it, wasting memory.



So are there any ideas out there on this? 



Much appreciated. 



Al LeMay

Virtuoso, Ltd. 

Quality Assurance Manager 

alemay@d... 

tele:  (xxx) xxx-xxxx 

cell:  (xxx) xxx-xxxx 



 <http://www.virtuoso.com/> http://www.virtuoso.com/ 



"Be joyful always; pray continually; give thanks in all circumstances." 

- 1 Thessalonians 5:18






Message #3 by "Samuel Engelman" <samuel_engelman@p...> on Tue, 20 Nov 2001 15:28:12 -0500
can you build an asp:table and dynamicaly put the controls in the cell 

of the

table?







|--------+--------------------------------->

|        |   "Al LeMay"                    |

|        |   <alemay@d...>     |

|        |                                 |

|        |                                 |

|        |   Tuesday November 20, 2001     |

|        |   02:35 PM                      |

|        |   Please respond to "ASP+"      |

|        |                                 |

|--------+--------------------------------->

  >------------------------------------------------------------|

  |                                                            |

  |      To:                                  "ASP+"           |

  |       <aspx@p...>                                  |

  |      cc:                                                   |

  |      Subject: [aspx] Placing a control dynamically onto a  |

  |       page...                                              |

  >------------------------------------------------------------|













All



I have a web form that has no controls on it. On page_load() it goes to

 a

database and retrieves a set of records. The records are then placed on

to Labels

and RadioButtons, and then dynamically added to the page through the

Controls.Add() method.=A0 Now here is the stickler, is there any "easy 

way" to

position the controls?



I am currently pondering writing the entire mess as HTML code to a buff

er.=A0 Then

reading the buffer to format the page.=A0 But one problem, I do not kno

w how large

to make the buffer. I could make it some arbitrary length, but then I m

ay over

run it. Or not completely fill it, wasting memory.



So are there any ideas out there on this?



Much appreciated.



Al LeMay

Virtuoso, Ltd.

Quality Assurance Manager

alemay@d...

tele:  (xxx) xxx-xxxx

cell:  (xxx) xxx-xxxx



http://www.virtuoso.com/



"Be joyful always; pray continually; give thanks in all circumstances."



- 1 Thessalonians 5:18

---

VBug Winter Conference 2001



Open Forum:  Dan Appleman will be hosting an open

forum at The .NET Developer's Conference on

29th November 2001.  The session will give

developers the chance to discuss and question

Dan on his experience with the .NET environment.

Dan has been programming Visual Basic since the

alpha version 1.0.  And with over 10 years

Visual Basic experience is well qualified to

help you on your road to being a .NET Guru.



http://www.vbug.co.uk/redirect.asp?url=3D39&id=3D17



---

You are currently subscribed to

aspx as: Samuel_Engelman@p...


$subst('Email.Unsub')









Message #4 by "Mark A. Struck" <mstruck@s...> on Tue, 20 Nov 2001 14:24:09 -0600
This is a multi-part message in MIME format.



------_=_NextPart_001_01C17201.4F565940

Content-Type: text/plain;

	charset="iso-8859-1"

Content-Transfer-Encoding: quoted-printable



If you have groups of controls you can put them in a placeholder

control. That way you only have to position the placeholder instead of

all the individual controls. Jeri is correct about the controls keeping

state. I store the state of my controls in XML that I store in

ViewState["State"], which gets stored in the page, this way everytime

the page gets loaded I can rebuild the controls from the XML.



Mark





-----Original Message-----

From: Jeri Lamy [mailto:jlamy@2...]

Sent: Tuesday, November 20, 2001 2:12 PM

To: ASP+

Subject: [aspx] RE: Placing a control dynamically onto a page...





By using the Style property of the controls, you can set a string that

can include positioning, like so:



protected System.Web.UI.WebControls.LinkButton Add;

Add.Style =3D "position:absolute; left:25px; top:10px";



You can put anything in the Style property just like you normally would

with a regular HTML or DHTML control.



There are, however, other issues you may want to consider when

dynamically creating controls through code.  For instance, anything

created in code must be created EVERY TIME you postback the page.  You

cannot check the IsPostback property in the Page_Load and only load them

the first time...they will disappear when you postback the page then.

In the IBuySpy demo, they load the dynamic controls in the Page_Init

function, and they are loaded every time.  The other problem that this

presents is, if you are wanting to do a postback to SAVE data that may

have been updated in your dynamically created controls, this will not

work...because the dynamic controls are not persisted on postback.



If this doesn't present problems for what you are trying to do, you

should still create them in the Page_Init function.  If you create them

in Page_Load, any events that you want to hook to server controls will

not be wired.  At least, I couldn't get them to fire.



Jeri Lamy

Sr. Programmer



-----Original Message-----

From: Al LeMay [mailto:alemay@d...]

Sent: Tuesday, November 20, 2001 12:36 PM

To: ASP+

Subject: [aspx] Placing a control dynamically onto a page...







All



I have a web form that has no controls on it. On page_load() it goes to

a database and retrieves a set of records. The records are then placed

onto Labels and RadioButtons, and then dynamically added to the page

through the Controls.Add() method.  Now here is the stickler, is there

any "easy way" to position the controls?



I am currently pondering writing the entire mess as HTML code to a

buffer.  Then reading the buffer to format the page.  But one problem, I

do not know how large to make the buffer. I could make it some arbitrary

length, but then I may over run it. Or not completely fill it, wasting

memory.



So are there any ideas out there on this?



Much appreciated.



Al LeMay

Virtuoso, Ltd.

Quality Assurance Manager

alemay@d...

tele:  (xxx) xxx-xxxx

cell:  (xxx) xxx-xxxx



 <http://www.virtuoso.com/> http://www.virtuoso.com/



"Be joyful always; pray continually; give thanks in all circumstances."

- 1 Thessalonians 5:18



---

VBug Winter Conference 2001



Open Forum: Dan Appleman will be hosting an open

forum at The .NET Developer's Conference on

29th November 2001. The session will give

developers the chance to discuss and question

Dan on his experience with the .NET environment.

Dan has been programming Visual Basic since the

alpha version 1.0. And with over 10 years

Visual Basic experience is well qualified to

help you on your road to being a .NET Guru.



http://www.vbug.co.uk/redirect.asp?url=3D39&id=3D17



---

You are currently subscribed to

aspx as: struckm@a...


$subst('Email.Unsub')






Message #5 by "Mark A. Struck" <mstruck@s...> on Tue, 20 Nov 2001 14:30:18 -0600
This is a multi-part message in MIME format.



------_=_NextPart_001_01C17202.2B73AF80

Content-Type: text/plain;

	charset="iso-8859-1"

Content-Transfer-Encoding: quoted-printable



Yes you can. Create the TableCell object and then

objTableCell.Controls.Add(control).



Mark



-----Original Message-----

From: Samuel Engelman [mailto:samuel_engelman@p...]

Sent: Tuesday, November 20, 2001 2:28 PM

To: ASP+

Subject: [aspx] Re: Placing a control dynamically onto a page...





can you build an asp:table and dynamicaly put the controls in the cell

of the

table?







|--------+--------------------------------->

|        |   "Al LeMay"                    |

|        |   <alemay@d...>     |

|        |                                 |

|        |                                 |

|        |   Tuesday November 20, 2001     |

|        |   02:35 PM                      |

|        |   Please respond to "ASP+"      |

|        |                                 |

|--------+--------------------------------->

  >------------------------------------------------------------|

  |                                                            |

  |      To:                                  "ASP+"           |

  |       <aspx@p...>                                  |

  |      cc:                                                   |

  |      Subject: [aspx] Placing a control dynamically onto a  |

  |       page...                                              |

  >------------------------------------------------------------|













All



I have a web form that has no controls on it. On page_load() it goes to

a

database and retrieves a set of records. The records are then placed

onto Labels

and RadioButtons, and then dynamically added to the page through the

Controls.Add() method.=A0 Now here is the stickler, is there any "easy

way" to

position the controls?



I am currently pondering writing the entire mess as HTML code to a

buffer.=A0 Then

reading the buffer to format the page.=A0 But one problem, I do not know

how large

to make the buffer. I could make it some arbitrary length, but then I

may over

run it. Or not completely fill it, wasting memory.



So are there any ideas out there on this?



Much appreciated.



Al LeMay

Virtuoso, Ltd.

Quality Assurance Manager

alemay@d...

tele:  (xxx) xxx-xxxx

cell:  (xxx) xxx-xxxx



http://www.virtuoso.com/



"Be joyful always; pray continually; give thanks in all circumstances."

- 1 Thessalonians 5:18

---

VBug Winter Conference 2001



Open Forum:  Dan Appleman will be hosting an open

forum at The .NET Developer's Conference on

29th November 2001.  The session will give

developers the chance to discuss and question

Dan on his experience with the .NET environment.

Dan has been programming Visual Basic since the

alpha version 1.0.  And with over 10 years

Visual Basic experience is well qualified to

help you on your road to being a .NET Guru.



http://www.vbug.co.uk/redirect.asp?url=3D39&id=3D17



---

You are currently subscribed to

aspx as: Samuel_Engelman@p...


$subst('Email.Unsub')









---

VBug Winter Conference 2001



Open Forum:  Dan Appleman will be hosting an open

forum at The .NET Developer's Conference on

29th November 2001.  The session will give

developers the chance to discuss and question

Dan on his experience with the .NET environment. 

Dan has been programming Visual Basic since the

alpha version 1.0.  And with over 10 years

Visual Basic experience is well qualified to

help you on your road to being a .NET Guru.



http://www.vbug.co.uk/redirect.asp?url=3D39&id=3D17



---

You are currently subscribed to

aspx as: struckm@a...


$subst('Email.Unsub')





  Return to Index