PC Review


Reply
Thread Tools Rate Thread

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

 
 
Bennett Haselton
Guest
Posts: n/a
 
      8th Nov 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
 
      8th Nov 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
Rate This Thread
Rate This Thread:

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
Event of a dynamically added user control doesn't fire niberhate Microsoft ASP .NET 1 26th Apr 2010 05:03 PM
User control property doesn't added into the dsigner... Ignacio Machin ( .NET/ C# MVP ) Microsoft C# .NET 4 30th May 2008 06:59 PM
User Control Doesn't Inherits the Property Added after using it... =?Utf-8?B?UHJhYmh1ZGhhcyBQZXRlcg==?= Microsoft VB .NET 2 9th Sep 2005 11:46 AM
events added to public folder calendar only show in user who added to it???? matthew hall Microsoft Outlook Calendar 0 21st Jan 2005 03:21 PM
Why doesn't my user control gets added to My User Control Tab Henke Microsoft Dot NET 5 9th Dec 2003 10:26 AM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 04:38 PM.