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

Dynamically adding controls

P: n/a
I have an ASP.Net page that simply generates a dynamic page using
Response.Write() statements to generate the HTML. This works great except that
one of the things I want to generate is a LinkButton. I know this can be done
by creating a Panel and adding it using Panel.Controls.Add(LinkButton) but the
problem is there are no controls on the page--I want to dynamically add
everything using simple Response.Write statements. But it doesn't look like I
can add a LinkButton this way.

This is an example of what I'm trying to do:

Response.Write("<br>")
Response.Write("This is some text. Next ")
Response.Write("<asp:LinkButton text=""Click"" onclick=""LinkButton_Click()""
/>")

The above doesn't actually create a LinkButton control, which is not entirely
surprising. Controls.Add(LinkButton) doesn't work either because it has to be
within the <Form> area which is why a Panel control is used.

So is there a way to generate a dynamic page like this without having to place
controls on the blank page beforehand?

May 26 '06 #1
Share this Question
Share on Google+
4 Replies


P: n/a
Mike,
That's correct, you can not, because what you are doing in this case is
taking over the normal ASP.NET Page processing model and instead, writing
HTML directly to the Response Stream, which is what the Page class would
normally do.

So, you have a decision to make. ASP.NET controls are created and rendered,
populated, and their events hooked up as a normal part of the Page lifecycle.
If instead you decide you want to write everything directly to the Response
object, you cannot have it "both ways".

Hope that helps.

Peter

--
Co-founder, Eggheadcafe.com developer portal:
http://www.eggheadcafe.com
UnBlog:
http://petesbloggerama.blogspot.com


"Mike Lowery" wrote:
I have an ASP.Net page that simply generates a dynamic page using
Response.Write() statements to generate the HTML. This works great except that
one of the things I want to generate is a LinkButton. I know this can be done
by creating a Panel and adding it using Panel.Controls.Add(LinkButton) but the
problem is there are no controls on the page--I want to dynamically add
everything using simple Response.Write statements. But it doesn't look like I
can add a LinkButton this way.

This is an example of what I'm trying to do:

Response.Write("<br>")
Response.Write("This is some text. Next ")
Response.Write("<asp:LinkButton text=""Click"" onclick=""LinkButton_Click()""
/>")

The above doesn't actually create a LinkButton control, which is not entirely
surprising. Controls.Add(LinkButton) doesn't work either because it has to be
within the <Form> area which is why a Panel control is used.

So is there a way to generate a dynamic page like this without having to place
controls on the blank page beforehand?

May 26 '06 #2

P: n/a
Can't you get to the form with something like this:

this.form1.Controls.Add(yadda) ?

May 26 '06 #3

P: n/a
Thanks Peter, that's what I was afraid of. Looks like I'll have to slap a table
on there to do what I want, or go a completely different route and use a
TreeView control.

"Peter Bromberg [C# MVP]" <pb*******@yahoo.nospammin.com> wrote in message
news:26**********************************@microsof t.com...
Mike,
That's correct, you can not, because what you are doing in this case is
taking over the normal ASP.NET Page processing model and instead, writing
HTML directly to the Response Stream, which is what the Page class would
normally do.

So, you have a decision to make. ASP.NET controls are created and rendered,
populated, and their events hooked up as a normal part of the Page lifecycle.
If instead you decide you want to write everything directly to the Response
object, you cannot have it "both ways".

Hope that helps.

Peter

--
Co-founder, Eggheadcafe.com developer portal:
http://www.eggheadcafe.com
UnBlog:
http://petesbloggerama.blogspot.com


"Mike Lowery" wrote:
I have an ASP.Net page that simply generates a dynamic page using
Response.Write() statements to generate the HTML. This works great except
that
one of the things I want to generate is a LinkButton. I know this can be
done
by creating a Panel and adding it using Panel.Controls.Add(LinkButton) but
the
problem is there are no controls on the page--I want to dynamically add
everything using simple Response.Write statements. But it doesn't look like
I
can add a LinkButton this way.

This is an example of what I'm trying to do:

Response.Write("<br>")
Response.Write("This is some text. Next ")
Response.Write("<asp:LinkButton text=""Click"" onclick=""LinkButton_Click()""
/>")

The above doesn't actually create a LinkButton control, which is not entirely
surprising. Controls.Add(LinkButton) doesn't work either because it has to
be
within the <Form> area which is why a Panel control is used.

So is there a way to generate a dynamic page like this without having to
place
controls on the blank page beforehand?

May 26 '06 #4

P: n/a
"Paul" <PA***********@YAHOO.COM> wrote in message
news:11**********************@y43g2000cwc.googlegr oups.com...
Can't you get to the form with something like this:

this.form1.Controls.Add(yadda) ?


You'd think so, but no...
May 26 '06 #5

This discussion thread is closed

Replies have been disabled for this discussion.