Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > WAP, VS2005 keeps changing my user control types!!

Reply
Thread Tools

WAP, VS2005 keeps changing my user control types!!

 
 
Tim_Mac
Guest
Posts: n/a
 
      09-06-2006
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


 
Reply With Quote
 
 
 
 
Steven Cheng[MSFT]
Guest
Posts: n/a
 
      09-07-2006
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><controls> section). 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.


 
Reply With Quote
 
 
 
 
Tim_Mac
Guest
Posts: n/a
 
      09-08-2006
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]" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> 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><controls> section). 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.
>
>



 
Reply With Quote
 
Steven Cheng[MSFT]
Guest
Posts: n/a
 
      09-11-2006
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.

 
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
User Control to Control Other User Control Jonathan Wood ASP .Net 4 02-02-2010 03:41 PM
User Control doesn't render in VS2005 Urs ASP .Net 1 07-01-2006 02:17 PM
persisting changes to a control outside a user control from the user control? Mad Scientist Jr ASP .Net 0 03-22-2006 08:02 AM
VS2005 Beta 2 - Web User Control Issue C Gatto ASP .Net 0 06-02-2005 06:16 PM
(VS2005) Cannot use web user control in the aspx page! InHyuk, Song ASP .Net 2 10-13-2004 03:59 PM



Advertisments