placing dynamic controls?

G

Guest

Hi peeps,

I'm trying to create some controls textboxes at runtime, based on the number
of items in a IETreeView that are checked. That I can do, I've got a place
holder and I can create the corrent number of controls.

The problem is that they appear next to each other.

I want to create the controls with some wording to the left of them (again,
dynamically generated). Normally id use <table> with two colums, one for the
text, and the other for the TextBox.

How can I do this with the Place Holder? I tried using a DIV, I could add
the controls to the DIV, but it threw a wobbly cos there was controls and
html. (something about it not containing a literal?).

So, how can I dynamically generate controls and then space them how I want
them?

Help!

Cheers


Dan
 
G

Guest

Create a Table control, add TableRow, add TableCell and add the TextBox in
its Controls collection. Then add second TableCell and add the label.
Continue this way, adding the second TableRow.
Then add the Table control to the PlaceHolder.

Hope that helps!
Regards,
Kostadin Kostov
 
G

Guest

Hey

Thanks that worked great - I hadn't twigged that you could treat the HTML
elements as controls like that!

One slight prob... these controls are on an ASP:panel, which I set it's
visible property to true/false during execution.

If I set the visible to false and then true, all my controls are gone! How
can I fix this, and use ViewState to "remember" what values have been entered
into the controls?

Cheers


Dan
 
G

Guest

Hi!
Well, when you make control like Panel invisible, you cannot use its
ViewState, neither you can use the controls inside it. A workaround that I ca
think of is instead of setting Visible=false, set style="display:none". Then,
I think, you can work with the child controls and ViewState.

Hope that helps!
Regards,
Kostadin Kostov
 
G

Guest

Just tried that with Panel.Style.Add("display", "none"); and the same thing
happens. The controls are there, and then it hides, and then when I go

Panel.Style.Add("display", "inline") - there's nothing in it.

Having said that, the controls are within a DIV within the panel, and that
DIV is still there, but all the controls aren't.

The reason I'm hiding/showing is I'm trying to create a wizard looking
thing, and so I have next/back buttons. clicking next hides the panel and
shows the next one, clicking back hides that and shows the one with the
controls. Except they aren't there! :(
 
G

Guest

I have implemented wizard like functionality in web and I think that the best
approach is to redirect to a different page, instead of hiding/showing
different controls. And you use the Session object for saving the data you
need between the pages of the wizard. Of course it's up to you to choose an
approach, that best suites you.

Regards,
Kostadin Kostov
 
G

Guest

Kostadin,

Let me just check I've got this right, cos my code might be stuffed if what
I've just realised is true :)

So, I run my page, and it shows a TreeView, which I can check a number of
items and click a button. That removes that panel and shows the next panel.
The code here finds out which buttons are checked, and automatically
generates a table/label/textbox for each checked item.

You fill that in, then click next again. This causes a postback. Now, before
I set the panel with the dynamic controls to invisible, I run a function to
get the values out of the textboxes...

TextBox tx = new TextBox();
tx = (TextBox) Panel.FindControl("thetextboxid");
string var = tx.Text;

Now then, this is crashing, saying that "object not set to an instance of an
object". Is that because I need to do FindControl on the Cell object I
created in the Row object of the Table object, or is it because my controls
are getting demolished on PostBack?

If it's the latter, that means I can never get the info out of the controls,
and my whole approach is stuffed!

Please reply :)

Cheers


Dan
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Members online

No members online now.

Forum statistics

Threads
473,754
Messages
2,569,526
Members
44,997
Latest member
mileyka

Latest Threads

Top