how come user control added to page doesn't get added to codebehind file?

Discussion in 'ASP .Net' started by Bennett Haselton, Nov 8, 2004.

  1. I create a new Web Form and drag a new Button onto it from the Web
    Forms toolbox tab, and then I drag a new instance of the UserPost user
    control that I created, by dragging and dropping the "UserPost.ascx"
    file listing from Solution Explorer. Both controls show up on the Web
    Form. But when I switch to the codebehind page, there is only a
    declaration for Button1:

    protected System.Web.UI.WebControls.Button Button1;

    and not one for UserPost1. Is this a bug? A feature? I'm not too
    lazy to type the declaration in myself, but anomalies like this are
    sometimes a sign that I'm doing something wrong...

    -Bennett
     
    Bennett Haselton, Nov 8, 2004
    #1
    1. Advertising

  2. Bennett Haselton

    John M Deal Guest

    Re: how come user control added to page doesn't get added to codebehindfile?

    You aren't doing anything wrong. User controls that you create in ascx
    file are different than custom controls that you drag in from the tool
    box. You can see this in the way the designer displays the gray blob
    for user controls as compared to the rendered output of the custom
    controls. You do have to add the declaration yourself in order to
    access the user control from codebehind. It is a pain in the back side
    but it seems to be the way it is.

    Have A Better One!

    John M Deal, MCP
    Necessity Software

    Bennett Haselton wrote:
    > I create a new Web Form and drag a new Button onto it from the Web
    > Forms toolbox tab, and then I drag a new instance of the UserPost user
    > control that I created, by dragging and dropping the "UserPost.ascx"
    > file listing from Solution Explorer. Both controls show up on the Web
    > Form. But when I switch to the codebehind page, there is only a
    > declaration for Button1:
    >
    > protected System.Web.UI.WebControls.Button Button1;
    >
    > and not one for UserPost1. Is this a bug? A feature? I'm not too
    > lazy to type the declaration in myself, but anomalies like this are
    > sometimes a sign that I'm doing something wrong...
    >
    > -Bennett
     
    John M Deal, Nov 8, 2004
    #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. John Saunders
    Replies:
    0
    Views:
    541
    John Saunders
    Jul 1, 2004
  2. grocery_stocker
    Replies:
    3
    Views:
    357
    Carl Banks
    Apr 10, 2009
  3. Chris
    Replies:
    3
    Views:
    695
    shusta guthnar
    Mar 26, 2010
  4. niberhate
    Replies:
    1
    Views:
    1,345
    Cubaman
    Apr 26, 2010
  5. Joshua Gunder via .NET 247

    Listbox in Custom Control doesn't keep listitems added on Page_Load of container page

    Joshua Gunder via .NET 247, May 13, 2004, in forum: ASP .Net Building Controls
    Replies:
    1
    Views:
    217
    Teemu Keiski
    May 13, 2004
Loading...

Share This Page