|
 |
aspx thread: Alternative to LoadControl or DataBinding????
Message #1 by agaisin@c... on Sat, 12 Jan 2002 23:43:03 +0000
|
|
I want to dynamically add server controls to pages and I am looking for an alternative to loadcontrol or
databinding b/c I am finding that they both have limitations (functional and stylistic).
Is the only way to dynamically at server/user/html/web controls by using loadcontrol or databinding with a template?
With classic html form controls one could and still can simply loop through and add them to a page like so:
for i=0 to 10
response.write("<input type=text id=texti>")
next
But can the same be done with server controls (runat=server) or must loadcontrol be used???????
for i=0 to 10
response.write("<asp:Textbox id=texti runat=server /><br>")
next
There are times where looping through and building a web form is much more straightforward - for example if you have a lot of css
you want to add to the controls etc... it's a lot more cumbersome (at least one line of code per attribute) to set all the
properties programmatically than it is to set declare the tag with the desired attributes in one line.
Of course if that (not wanting to set styles programmatically) were the only issue then databinding with a
datalist/datagrid/datarepeater would be great. But that's not always such a simple solution either. For example, I ran into a
situation where I was building menus of LinkButtons - the catch was that if there are too many they should continue on to the next
line. Now again, I could (and tried to) use repeatdirection=horizontal and repeatcolumns=6 but then if you use repeatLayout=table
then the second row of menus are not centered. So I tried using repeatLayout=flow and displaying each linkbutton in span tags and
putting it all b/w center tags to center it. Now that worked - but it's raw and it's difficult (if not impossible) to truly
customize the display. For example if I wanted to set different properties for the second row than for the first there's no simple
clean way.
Yes, I could use place code in the ItemDataBound event to conditionally render the menus depending on whether they are in the first
or second row...
But, to me it's clear by now that databinding has it's limitations and isn't always the best/easiest/cleanest solution! Neither is
dynamically loading controls using LoadControl and then programmatically setting properties...
For example, there's this awesome IE TreeView web control, but the only examples of usage I've seen is either with hardcoded values
for nodes or populating from xml files and when it comes to binding it to a database the usage gets extremely messy!!! I think it
would be simples to be able to loop and build the control using a looping construct.
Any ideas??? Any thoughts???
Is it possible to add server controls using response.write in page_load or does it have to be in a different method or is it simply
not possible?
This is really bothering me now and it feels like a serious limitation!!!!
Arthur Gaisin,
agaisi1@g...
Message #2 by "Dan Green" <dangreen@b...> on Sun, 13 Jan 2002 17:20:54 +1100
|
|
Arthur,
I haven't parsed your entire email but you may find some sanctuary in
judicious use of Page.Controls.Add() in conjunction with PlaceHolder
controls.
Dan Green
[ http://dotnetdan.com -- putting the dan in .net ]
|
|
 |