By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
446,266 Members | 1,816 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 446,266 IT Pros & Developers. It's quick & easy.

placing dynamic controls?

P: n/a
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
Nov 19 '05 #1
Share this Question
Share on Google+
6 Replies


P: n/a
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

"dhnriverside" wrote:
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

Nov 19 '05 #2

P: n/a
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

"Kostadin Kostov" wrote:
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

"dhnriverside" wrote:
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

Nov 19 '05 #3

P: n/a
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

"dhnriverside" wrote:
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

"Kostadin Kostov" wrote:
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

"dhnriverside" wrote:
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

Nov 19 '05 #4

P: n/a
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! :(

"Kostadin Kostov" wrote:
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

"dhnriverside" wrote:
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

"Kostadin Kostov" wrote:
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

"dhnriverside" wrote:

> 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

Nov 19 '05 #5

P: n/a
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

"dhnriverside" wrote:
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! :(

"Kostadin Kostov" wrote:
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

"dhnriverside" wrote:
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

"Kostadin Kostov" wrote:

> 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
>
> "dhnriverside" wrote:
>
> > 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

Nov 19 '05 #6

P: n/a
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

"Kostadin Kostov" wrote:
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

"dhnriverside" wrote:
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! :(

"Kostadin Kostov" wrote:
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

"dhnriverside" wrote:

> 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
>
> "Kostadin Kostov" wrote:
>
> > 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
> >
> > "dhnriverside" wrote:
> >
> > > 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

Nov 19 '05 #7

This discussion thread is closed

Replies have been disabled for this discussion.