Web user control

L

Lamis

Hi,
I just started with .Net 2.0 and have created a few user controls that I
would like now to use in my webpage. I need to create them in my onload and
add them into a table on the aspx page. I am using C#. My proble is that I
get exception "Use the "new" keyword to create an object of instance" "Check
to determin if the object is null before calling the method".
It seems to me that InitializeComponents() method has not executed and all
labels, buttons and dropdown list in my component has value null..
Any Idea how to create instance of my components dynamically and show them
in a aspx page???
 
T

Teemu Keiski

Hi,

you basically cannot instantiate user control with new keyword, since that
would instantiate only UC's code-behind class if any. The markup side would
not be parsed and associated with the instance.

Instead, use

Control c = Page.LoadControl("control.ascx");
 

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

Forum statistics

Threads
473,768
Messages
2,569,574
Members
45,048
Latest member
verona

Latest Threads

Top