Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > how come user control added to page doesn't get added to codebehind file?

Reply
Thread Tools

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

 
 
Bennett Haselton
Guest
Posts: n/a
 
      11-08-2004
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
 
Reply With Quote
 
 
 
 
John M Deal
Guest
Posts: n/a
 
      11-08-2004
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

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
How do I get access to the User.Identity.Name in the codebehind mo =?Utf-8?B?dnZlbms=?= ASP .Net 1 09-26-2005 11:19 PM
Re: ListBox Items not accessible by codebehind when added from JScript John Saunders ASP .Net 0 07-01-2004 01:25 PM
Shared User Control - with Codebehind Marcos MOS ASP .Net 3 04-13-2004 10:32 PM
Come One, Come All Jess Guim Digital Photography 0 12-02-2003 04:43 PM
Treeview: Dynamically added treenodes not available in codebehind rune solheim ASP .Net Web Controls 0 09-24-2003 06:13 AM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57