|
.net
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
WAP, VS2005 keeps changing my user control types!!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 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/subscriptions/managednewsgroups/default.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/subscriptions/support/default.aspx. ================================================== This posting is provided "AS IS" with no warranties, and confers no rights. 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 Show quote :) but i can certainly live with your solution. thanks again tim "Steven Cheng[MSFT]" <stch***@online.microsoft.com> wrote in message news:ggGeovi0GHA.396@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><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/subscriptions/managednewsgroups/default.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/subscriptions/support/default.aspx. > > ================================================== > > > > This posting is provided "AS IS" with no warranties, and confers no > rights. > > 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/feedback/default.aspx?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. |
|||||||||||||||||||||||