473,326 Members | 2,133 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,326 software developers and data experts.

Dynamically adding controls

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
4 2163
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
Can't you get to the form with something like this:

this.form1.Controls.Add(yadda) ?

May 26 '06 #3
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
"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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: DotNetJunky | last post by:
I have built a control that runs an on-line help system. Depending on the category you selected via dropdownlist, it goes out and gets the child subcategories, and if there are any, adds a new...
0
by: sameer mowade via .NET 247 | last post by:
Hello All, I have problem while dynamically removing row from the Datagrid which i have added dynamically as shown in the following code snippet. The problem is that while removing dynamically...
8
by: Donald Xie | last post by:
Hi, I noticed an interesting effect when working with controls that are dynamically loaded. For instance, on a web form with a PlaceHolder control named ImageHolder, I dynamically add an image...
9
by: netasp | last post by:
hi all, how can I populate one aspx form when page is loading based on page ID? for example: loading page A (to search for VB code) would display labels and texboxes, dropdown lists all related...
3
by: Mark Denardo | last post by:
I'm trying to dynamically create and add controls to a web page: Label obj1 = new Label(); DropDownList obj2 = new DropDownList(); Controls.Add(obj1); Controls.Add(obj2); But I get the...
6
by: | last post by:
I have made some user controls with custom properties. I can set those properties on instances of my user controls, and I have programmed my user control to do useful visual things in response to...
9
by: Chris | last post by:
I am dynamically adding a user control to each row in a gridview. The reason I am doing it dynamically is the user control is different depending on certain data in the gridview. The gridview...
4
by: Lewis Holmes | last post by:
Hi I have the following situation in one of my asp.net pages. The user can add multiple table rows to a form by selecting a button. These rows can contain asp.net controls. When this button is...
7
by: =?Utf-8?B?V2ViQnVpbGRlcjQ1MQ==?= | last post by:
I'm adding subheadings to a gridview. Each sub head has a few link buttons. I'm adding the controls in the rowdatabound event code follows: sorry about the length here. I have to be missing...
1
by: semomaniz | last post by:
I have a form where i have created the form dynamically. First i manually added a panel control to the web page. Then i added another panel dynamically and inside this panel i created tables. I have...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.