@Register Programmatically

  • Thread starter Yet another C# coder
  • Start date
Y

Yet another C# coder

Dear all,

Is it possible to register a UserControl Programmatically?
I am using a xml/xslt transformer to create some controls and then use the
Page.ParseControl to create
the webcontrols. I was wondering how I must add my UserControls without
adding any @Register tag inside my aspx file.

Thanx.
 
G

Grant Merwitz

This is how you load a control programmatically:

string LoadControlStr = "/usercontrols/mycontrol.ascx"; //this would be
the location of your control
Control thisControl = LoadControl(LoadControlstr);
pnlContent.Controls.Add(thisControl); //this would be a panel on your
page

HTH
 
S

Scott Mitchell [MVP]

Yet said:
Dear all,

Is it possible to register a UserControl Programmatically?
I am using a xml/xslt transformer to create some controls and then use the
Page.ParseControl to create
the webcontrols. I was wondering how I must add my UserControls without
adding any @Register tag inside my aspx file.

You can load the control dynamically as Grant noted. However, be aware
that there are a host of potential 'issues' with dynamically loaded
controls IF you are doing postbacks. In essence, a lot of the inner
workings that the ASP.NET page model handles for you automatically,
you'll need to do.

I've got a number of articles on working with dynamic controls, check
these two out to get started, though:

Dynamic Controls in ASP.NET
http://aspnet.4guysfromrolla.com/articles/081402-1.aspx

Creating Dynamic Data Entry User Interfaces
http://msdn.microsoft.com/asp.net/default.aspx?pull=/library/en-us/dnaspp/html/DynamicUI.asp


hth
 

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,994
Messages
2,570,223
Members
46,810
Latest member
Kassie0918

Latest Threads

Top