WAP, VS2005 keeps changing my user control types!!

Discussion in 'ASP .Net' started by Tim_Mac, Sep 6, 2006.

  1. Tim_Mac

    Tim_Mac Guest

    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
     
    Tim_Mac, Sep 6, 2006
    #1
    1. Advertising

  2. 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.
     
    Steven Cheng[MSFT], Sep 7, 2006
    #2
    1. Advertising

  3. Tim_Mac

    Tim_Mac Guest

    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]" <> wrote in message
    news:...
    > 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.
    >
    >
     
    Tim_Mac, Sep 8, 2006
    #3
  4. 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.
     
    Steven Cheng[MSFT], Sep 11, 2006
    #4
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. methi
    Replies:
    16
    Views:
    2,276
    Martin Thompson
    Jul 18, 2005
  2. Karl Lang
    Replies:
    0
    Views:
    465
    Karl Lang
    Sep 24, 2004
  3. Nathan Sokalski
    Replies:
    5
    Views:
    1,478
    Nathan Sokalski
    Oct 3, 2005
  4. Aaron Whiffin
    Replies:
    0
    Views:
    607
    Aaron Whiffin
    Sep 4, 2003
  5. bernadou

    SessionID keeps changing?

    bernadou, Dec 2, 2005, in forum: ASP General
    Replies:
    0
    Views:
    106
    bernadou
    Dec 2, 2005
Loading...

Share This Page