Dynamic, Run-Time Insertion of Controls

G

Guest

I want to be able to create and insert an ASP.NET control into a page after a
control that already exists on that page at Run-Time. I'm pretty sure that
that can be done but I'm not exactly sure what the syntax would be and then
how you access the control after the fact at PostBack, etc.

Alex
 
K

Ken Cox [Microsoft MVP]

Hi Alex,

You can put a PlaceHolder control after the existing control and then add
the new (dynamic) control to its Controls collection.

Is this a case where you could create the control a design-time but hide it
(make visible=false) until you need it?

Ken
 
G

Guest

No, I wouldn't be creating it in design-time. Well, actually, the scenario is
that I could create ONE of the controls in design-time, but I may have to
create X controls like that one dynamically at run-time. But I really don't
know how to create the control that way, to set it's event handlers, etc.,
etc.

Alex
 
S

Steven Cheng[MSFT]

Hi Alex,

As for the dynamically control creating question you mentioned, would you
provide some further detailed page or code logic or would you use a simple
page to illustrate the requirement in your scenario?

For generice info on dynamically creating ASP.NET web server controls, you
can refer to the following msdn and knowledge base artciles:

#HOW TO: Dynamically Create Controls in ASP.NET by Using Visual C# .NET
http://support.microsoft.com/kb/317794/en-us

http://msdn2.microsoft.com/en-us/library/kyt0fzt1.aspx


#How to: Dynamically Bind Event Handlers at Run Time in ASP.NET Web Pages
http://msdn2.microsoft.com/en-us/library/t3d01ft1.aspx

Regards,

Steven Cheng

Microsoft MSDN Online Support Lead


==================================================

When responding to posts, please "Reply to Group" via your newsreader so
that others may learn and benefit from your issue.

==================================================


This posting is provided "AS IS" with no warranties, and confers no rights.



Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)
 
S

Steven Cheng[MSFT]

Hey Alex,

Have you got any further ideas on this issue or does the information in my
last reply helps you a little? Please feel free to post here if there is
anything we can help you.

Regards,

Steven Cheng
Microsoft MSDN Online Support Lead


==================================================

When responding to posts, please "Reply to Group" via your newsreader so
that others may learn and benefit from your issue.

==================================================


This posting is provided "AS IS" with no warranties, and confers no rights.



Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)
 

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

Members online

No members online now.

Forum statistics

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

Latest Threads

Top