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

  • Thread starter Bennett Haselton
  • Start date
B

Bennett Haselton

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
 
J

John M Deal

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
 

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,768
Messages
2,569,574
Members
45,048
Latest member
verona

Latest Threads

Top