473,574 Members | 2,623 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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:LinkButto n text=""Click"" onclick=""LinkB utton_Click()""
/>")

The above doesn't actually create a LinkButton control, which is not entirely
surprising. Controls.Add(Li nkButton) 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 2194
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:LinkButto n text=""Click"" onclick=""LinkB utton_Click()""
/>")

The above doesn't actually create a LinkButton control, which is not entirely
surprising. Controls.Add(Li nkButton) 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.Cont rols.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*******@yaho o.nospammin.com > wrote in message
news:26******** *************** ***********@mic rosoft.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:LinkButto n text=""Click"" onclick=""LinkB utton_Click()""
/>")

The above doesn't actually create a LinkButton control, which is not entirely
surprising. Controls.Add(Li nkButton) 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.goo glegroups.com.. .
Can't you get to the form with something like this:

this.form1.Cont rols.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
5465
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 dropdownlist to the screen for selection. This continues until there are no children, and then it checks for a help article list based on that last...
0
2463
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 added row it also removes the row at the end along with the added row. Plz tell me if, I am missing any thing. Code </asp:datagrid>
8
4304
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 button at runtime: //----- Code snippet protected System.Web.UI.WebControls.PlaceHolder ImageHolder; private void Page_Load(object sender,...
9
7029
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 to VB, plus the address bar would show something like this: www.somethinghere?id=3 and if you change number 3 from the address bar to (for example)...
3
5478
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 following error when the DDL is added (but not the Label): "Control 'ctl07' of type 'DropDownList' must be placed inside a form tag
6
11062
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 how those properties are set. I want to be able to do two other things: a) add User control instances to my page, filling in the place of...
9
7916
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 contains a placeholder and I add the control to it, the user control is a formview bound to an object datsource. This works great until I post back the...
4
4470
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 selected, the row is added using JavaScript. The script uses cloneNode to clone a hidden template row and all of its children and then adds the new...
7
6189
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 something. The buttons show up and post back, but the events do not fire. any help would be appreciated!!! Thank you. protected void...
1
4884
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 set text boxes and labels inside the table rows. I then added a button. All of these are done through code. The problem that i am having is i can...
0
7814
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
7737
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
8075
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
0
8253
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
0
6471
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
1
5632
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
3752
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
1
1356
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
1072
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

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.