473,511 Members | 14,990 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

WAP, VS2005 keeps changing my user control types!!

hi,
i'm using a web application project in VS2005. i have a User Control
Template.ascx in the '~/UserControls' folder with the following signature:
public partial class GpTemplate : System.Web.UI.UserControl

I have the user control registered in web.config as follows:
<pages>
<controls>
<add tagPrefix="uc1" src="~/UserControls/Template.ascx"
tagName="GpTemplate"/>

Then in my aspx pages, i use the following code to declare an instance of
the user control
<uc1:GpTemplate ID="Template1" runat="server"></uc1:GpTemplate>

this works fine but as soon as any change is made to the page in VS, i get a
runtime error when next browsing the page, because the partial
ascx.designer.cs file has changed the type of the user control to a generic
System.Web.UI.UserControl. this obviously breaks all the code in the
control that references any of its own controls or properties, e.g.
this.Button1 does not exist in a System.Web.UI.UserControl but it does exist
in the property class GpTemplate.

how can i stop this very annoying behaviour? at the moment i have to do a
text replace for every build on the partial designer classes to fix the user
control type.

thanks in advance.
tim
----------------------------------------
blog: http://tim.mackey.ie
Sep 6 '06 #1
3 2183
Hello Tim,

Nice to see you again.

As for the global usercontrol's reference type in page (when using VS 2005
Web application project), I've just perfomed some test against a Web
Applicaiton project on my side and did find the behavior you mentioned.

Actually, this behavior is due to the limitation of globally registered
usercontrols in web.config file(<pages><controlssection). Since the
usercontrol registered there doesn't add a @register directive(like below)
, then the page parser can not determine the concrete type of the
usercontrol, thus, use the base class UserControl instead.

<%@ Register TagName="" TagPrefix="" Src=""%>

Currently, based on my test, a possible approach is manually declare the
usercontrol member variable in our page's codebehind file(not the
designer.cs file). Because ASP.NET 2.0 Web application project use the
following to file to compile the two partial page class:

** pagename.aspx.cs

**pagename.aspx.designer.cs

and pagename.aspx.deisgner.cs is changeable(whenever we modify the page),
therefore, we should manually declare the usercontrol member in the
pagename.aspx.cs file which is not auto generated by IDE. e.g.

#first remove the originally generated member variable for your usercontrol
in the designer.cs file(which is of UserControl class), then add the
concrete usercontrol type member variable in main cs codebehind as below:

========================
namespace WebApplication1
{
public partial class _Default : System.Web.UI.Page
{
protected GpTemplate gp1;

.........................
}
}
====================

After that, the page parser will automatically use this member variable to
associate the usercontrol in aspx template and won't regenerate the
UserControl type member in designer.cs file.

Hope this helps.

Sincerely,

Steven Cheng

Microsoft MSDN Online Support Lead

==================================================

Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/subscripti...ult.aspx#notif
ications.

Note: The MSDN Managed Newsgroup support offering is for non-urgent issues
where an initial response from the community or a Microsoft Support
Engineer within 1 business day is acceptable. Please note that each follow
up response may take approximately 2 business days as the support
professional working with you may need further investigation to reach the
most efficient resolution. The offering is not appropriate for situations
that require urgent, real-time or phone-based interactions or complex
project analysis and dump analysis issues. Issues of this nature are best
handled working with a dedicated Microsoft Support Engineer by contacting
Microsoft Customer Support Services (CSS) at
http://msdn.microsoft.com/subscripti...t/default.aspx.

==================================================

This posting is provided "AS IS" with no warranties, and confers no rights.
Sep 7 '06 #2
hi STeven,
hopefully the next version of the page parser will scan the web.config for a
matching tag prefix + tag name, and pick up the actual type of the control
:) but i can certainly live with your solution. thanks again
tim
"Steven Cheng[MSFT]" <st*****@online.microsoft.comwrote in message
news:gg*************@TK2MSFTNGXA01.phx.gbl...
Hello Tim,

Nice to see you again.

As for the global usercontrol's reference type in page (when using VS 2005
Web application project), I've just perfomed some test against a Web
Applicaiton project on my side and did find the behavior you mentioned.

Actually, this behavior is due to the limitation of globally registered
usercontrols in web.config file(<pages><controlssection). Since the
usercontrol registered there doesn't add a @register directive(like
below)
, then the page parser can not determine the concrete type of the
usercontrol, thus, use the base class UserControl instead.

<%@ Register TagName="" TagPrefix="" Src=""%>

Currently, based on my test, a possible approach is manually declare the
usercontrol member variable in our page's codebehind file(not the
designer.cs file). Because ASP.NET 2.0 Web application project use the
following to file to compile the two partial page class:

** pagename.aspx.cs

**pagename.aspx.designer.cs

and pagename.aspx.deisgner.cs is changeable(whenever we modify the page),
therefore, we should manually declare the usercontrol member in the
pagename.aspx.cs file which is not auto generated by IDE. e.g.

#first remove the originally generated member variable for your
usercontrol
in the designer.cs file(which is of UserControl class), then add the
concrete usercontrol type member variable in main cs codebehind as below:

========================
namespace WebApplication1
{
public partial class _Default : System.Web.UI.Page
{
protected GpTemplate gp1;

.........................
}
}
====================

After that, the page parser will automatically use this member variable to
associate the usercontrol in aspx template and won't regenerate the
UserControl type member in designer.cs file.

Hope this helps.

Sincerely,

Steven Cheng

Microsoft MSDN Online Support Lead

==================================================

Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/subscripti...ult.aspx#notif
ications.

Note: The MSDN Managed Newsgroup support offering is for non-urgent issues
where an initial response from the community or a Microsoft Support
Engineer within 1 business day is acceptable. Please note that each follow
up response may take approximately 2 business days as the support
professional working with you may need further investigation to reach the
most efficient resolution. The offering is not appropriate for situations
that require urgent, real-time or phone-based interactions or complex
project analysis and dump analysis issues. Issues of this nature are best
handled working with a dedicated Microsoft Support Engineer by contacting
Microsoft Customer Support Services (CSS) at
http://msdn.microsoft.com/subscripti...t/default.aspx.

==================================================

This posting is provided "AS IS" with no warranties, and confers no
rights.


Sep 8 '06 #3
Thanks for your followup Tim,

Yes, I agree that it would be more perfect if the VS IDE can support all of
the runtime supported behavior at design-time development. Actually
there're many such requests pending, such as the design-time support of
global masterpage, nested master page ....

Anyway, I would always suggest you submit your requests or vote existing
requests on our feedback site:

#Visual Studio and .NET Framework Feedback
Product Feedback
http://connect.microsoft.com/feedbac...spx?SiteID=210

Your feedback and comments is really appreciated!

Sincerely,

Steven Cheng

Microsoft MSDN Online Support Lead

This posting is provided "AS IS" with no warranties, and confers no rights.

Sep 11 '06 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
1571
by: Jason Winters | last post by:
I have implemented a user control in c# .net 2002 but the problem is that the control keeps disappearing off of the form for no reason. I am not making any changing to the form or the control. It...
0
911
by: C Gatto | last post by:
Hello, In a VS2003 app I have an aspx page (default.aspx) with a PlaceHolder defined (phMain). In my aspx code-behind I am dynamically creating a reference to a web user control...
4
1782
by: bill | last post by:
I have a Repeater control in a web user control. The web user control has a public method named PopulateRepeater which takes an ID as an parameter and populates the repeater control based on the...
11
11533
by: John J. Hughes II | last post by:
I have a DataGridView displaying data from a DataSet. To the right of that I have a custom user control which displays one of the data set fields. The custom user control is bound to the data set...
0
941
by: Chris Davoli | last post by:
VS2005 - How do I reference a User Control from the ASPX page that I have placed the user control on? Here is the code I used from VS2003 and it worked, but for VS2005 it gives me a null reference...
5
2150
by: rn5a | last post by:
Consider the following user control which resides in Address.ascx: <script runat="server"> Public Property Address() As String Get Address = txtAddress.Text End Get Set(ByVal value As String)...
9
1627
by: aaronluna | last post by:
Hi All, I was wondering if it is possible to easily convert an asp.net user control (.ascx) into an equivalent windows app. I plan on simply duplicating the user control in a c# windows app...
1
1046
by: Rotsey | last post by:
Hi, I am using VS2005. I have created a user control with some properties. I am trying to pass the user control object to a method in a another class. But I cannot see the user control...
2
3004
by: HammRadio | last post by:
I am exploring converting my web app (current Framework 1.1) to Framework 2.0. Everything went smoothly save for one item. To reduce the trips to the database, when loading user controls (like a...
0
7237
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
7137
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
1
7074
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
5659
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
5063
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
3219
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
3210
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1572
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
1
780
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.