Web user control

Discussion in 'ASP .Net Web Controls' started by Lamis, Sep 24, 2007.

  1. Lamis

    Lamis Guest

    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???

    --
    LZ
    Lamis, Sep 24, 2007
    #1
    1. Advertising

  2. Lamis

    Teemu Keiski Guest

    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");


    --
    Teemu Keiski
    AspInsider, ASP.NET MVP
    http://blogs.aspadvice.com/joteke
    http://teemukeiski.net

    "Lamis" <> wrote in message
    news:...
    > 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???
    >
    > --
    > LZ
    Teemu Keiski, Sep 24, 2007
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Reny J Joseph Thuthikattu
    Replies:
    1
    Views:
    539
    =?Utf-8?B?UHJha2FzaC5ORVQ=?=
    Dec 30, 2004
  2. ABC
    Replies:
    1
    Views:
    2,621
    Larry
    Oct 4, 2005
  3. ABC
    Replies:
    0
    Views:
    468
  4. Mad Scientist Jr
    Replies:
    0
    Views:
    622
    Mad Scientist Jr
    Mar 22, 2006
  5. ABC
    Replies:
    0
    Views:
    183
Loading...

Share This Page