Design Time Rendering User Control?

Discussion in 'ASP .Net Building Controls' started by Bill Cohagan, Jul 21, 2006.

  1. Bill Cohagan

    Bill Cohagan Guest

    I've created a user control (not a custom control) consisting of a table
    with a single row containing three cells, each cell containing a button.
    Following is the code for this user control.

    <%@ Control Language="C#" AutoEventWireup="true"
    CodeFile="NewEditDeleteButtons.ascx.cs"
    Inherits="UserControls_NewEditDeleteButtons" %>
    <%@ Register TagPrefix="ctrl" Namespace="IDWeb.Web.Control"
    Assembly="IDWeb.Web" %>
    <asp:Table ID="AEDBTable" runat="server">
    <asp:TableRow runat="server">
    <asp:TableCell ID="TableCell26" runat="server" CssClass="data">
    <ctrl:Button ID="btnNew" runat="server" Text="+"
    OnClick="btnNew_Click"/>
    </asp:TableCell>
    <asp:TableCell ID="TableCell1" runat="server" CssClass="data">
    <ctrl:Button ID="btnEdit" runat="server" Text="e"
    OnClick="btnEdit_Click"/>
    </asp:TableCell>
    <asp:TableCell ID="TableCell27" runat="server" CssClass="data">
    <ctrl:Button ID="btnDelete" runat="server" Text="X"
    OnClick="btnDelete_Click"/>
    </asp:TableCell>
    </asp:TableRow>
    </asp:Table>

    This user control works fine at runtime and renders as expected. In design
    view however the page containing the NewEditDeleteButtons tag doesn't show
    anything for this control. Is there a way I can get it to render in the
    designer?

    TIA,
    Bill Cohagan
     
    Bill Cohagan, Jul 21, 2006
    #1
    1. Advertisements

  2. Bill Cohagan

    Riki Guest

    I'm suspecting the custom button controls that you're using.

    Try replacing the custom buttons with standard buttons, and see if that
    helps.
     
    Riki, Jul 22, 2006
    #2
    1. Advertisements

  3. Bill Cohagan

    Bill Cohagan Guest

    Riki
    Thank, but I already tried that. Should have mentioned that in my
    posting. FWIW, the custom button (at this point) is trivial anyway:

    namespace IDWeb.Web.Control
    {
    public class Button : System.Web.UI.WebControls.Button
    {
    public Button()
    {
    }
    }
    }
     
    Bill Cohagan, Jul 22, 2006
    #3
  4. Hi Bill,

    Thank you for your post.

    Depending on which ASP.NET version you are using, the answer to your
    question varies:

    1) If you are using ASP.NET 1.1, the UserControl's design-time rendering is
    very limited and the behavior you're experiencing is expected.

    2) If you are using ASP.NET 2.0, the UserControl's design-time rendering
    should reflect the controls it's using. However, if the custom control
    (IDWeb.Web.Control.Button) is placed under the website's App_Code folder,
    due to ASP.NET 2.0 compilation model, it will show the custom control on
    UserControl successfully, but will not show correctly if the UserControl is
    used in WebForm or another UserControl again. You need to place the custom
    control in a separate Class Library to get correct design-time rendering.

    Hope this helps. Please feel free to post here if anything is unclear.

    Regards,
    Walter Wang (, remove 'online.')
    Microsoft Online Community Support

    ==================================================
    When responding to posts, please "Reply to Group" via your newsreader so
    that others may learn and benefit from your issue.
    ==================================================

    This posting is provided "AS IS" with no warranties, and confers no rights.
     
    Walter Wang [MSFT], Jul 24, 2006
    #4
  5. Bill Cohagan

    Bill Cohagan Guest

    Walter
    Thanks for the suggestions; however the button custom control is already
    in a dll. I'm using ASP.Net 2.0. Following is the code for the user control
    as well:

    <%@ Control Language="C#" AutoEventWireup="true"
    CodeFile="NewEditDeleteButtons.ascx.cs"
    Inherits="UserControls_NewEditDeleteButtons" %>
    <%@ Register TagPrefix="ctrl" Namespace="IDWeb.Web.Control"
    Assembly="IDWeb.Web" %>
    <asp:Table ID="AEDBTable" runat="server">
    <asp:TableRow runat="server">
    <asp:TableCell ID="TableCell26" runat="server" CssClass="data">
    <ctrl:Button ID="btnNew" runat="server" Text="+"
    OnClick="btnNew_Click"/>
    </asp:TableCell>
    <asp:TableCell ID="TableCell1" runat="server" CssClass="data">
    <ctrl:Button ID="btnEdit" runat="server" Text="e"
    OnClick="btnEdit_Click"/>
    </asp:TableCell>
    <asp:TableCell ID="TableCell27" runat="server" CssClass="data">
    <ctrl:Button ID="btnDelete" runat="server" Text="X"
    OnClick="btnDelete_Click"/>
    </asp:TableCell>
    </asp:TableRow>
    </asp:Table>

    Note the Register element referencing the IDWeb.Web assembly. If I
    understand your response correctly, you're saying this should work as-is,
    right?

    Regards,
    Bill
     
    Bill Cohagan, Jul 25, 2006
    #5
  6. Sorry for the typo in previous reply, should be "inherits from WebControl".

    Regards,
    Walter Wang (, remove 'online.')
    Microsoft Online Community Support

    ==================================================
    When responding to posts, please "Reply to Group" via your newsreader so
    that others may learn and benefit from your issue.
    ==================================================

    This posting is provided "AS IS" with no warranties, and confers no rights.
     
    Walter Wang [MSFT], Jul 26, 2006
    #6
  7. Bill Cohagan

    Bill Cohagan Guest

    Walter
    Thanks for the suggestions; however your solution suggests that I should
    *not* be having this problem since my custom controls are *not* placed in
    App_Code. In any case, for test purposes, I changes my code to use
    asp:Button rather than the custom control ctrl:Button and the problem is
    still there; i.e., the web control does NOT render at all in designer.

    Any other ideas?

    Thanks again,
    Bill
     
    Bill Cohagan, Jul 27, 2006
    #7
  8. Hi Bill,

    Thank you for your update.

    Have you tried my sample project in my second post in this thread? You may
    have to use Outlook Express to download the attachment. If you have
    difficulty to download the attachment, email me and I will send the project
    to you.

    We're actually handling two questions here:
    1) Design-time rendering of custom control

    You can find more information here:

    #Adding Design-Time Support to ASP.NET Controls
    http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dnaspp/html
    /ASPNet-AddDesignTimeSupport.asp

    Normally, when you inherit from a control that is already associated with a
    control designer, you don't have to create a designer.

    If you're building a control from scratch or building a composite control,
    you may have to create a control designer and associate it with the control.

    2) Design-time rendering of user control

    Before Visual Studio 2005, the design-time rendering of user control is
    very limited. However, in Visual Studio 2005, it should render correctly.
    Please test the sample project and tell me the result, thanks!

    Or you can send me your project which can reproduce the issue so that we
    can check whether or not this is environment specific.

    Regards,
    Walter Wang (, remove 'online.')
    Microsoft Online Community Support

    ==================================================
    When responding to posts, please "Reply to Group" via your newsreader so
    that others may learn and benefit from your issue.
    ==================================================

    This posting is provided "AS IS" with no warranties, and confers no rights.
     
    Walter Wang [MSFT], Jul 28, 2006
    #8
  9. Bill Cohagan

    Bill Cohagan Guest

    Walter
    I will try your sample project and report back.

    Thanks,
    Bill
     
    Bill Cohagan, Jul 29, 2006
    #9
  10. Bill Cohagan

    Bill Cohagan Guest

    Walter
    Please examine my code again. Your screenshot shows that the control does
    NOT render when it is inside a table cell. See the small empty box below
    the row containing the 3 buttons? The instance that DOES render is the one
    before the one in the table cell.

    Regards,
    Bill
     
    Bill Cohagan, Aug 3, 2006
    #10
  11. Hi Bill,

    Thanks. I overlooked that table cell.

    I'm now able to reproduce the issue you described. Creating a very simple
    UserControl with an <asp:Button> and use this UserControl inside
    <asp:Table><asp:TableRow><asp:TableCell> will not render the UserControl
    correctly.

    I'm currently searching in internal database and will consult with product
    team on this. In the meanwhile, you can submit your feedback here:

    http://connect.microsoft.com/site/sitehome.aspx?SiteID=210

    Thanks for your help!

    Regards,
    Walter Wang (, remove 'online.')
    Microsoft Online Community Support

    ==================================================
    When responding to posts, please "Reply to Group" via your newsreader so
    that others may learn and benefit from your issue.
    ==================================================

    This posting is provided "AS IS" with no warranties, and confers no rights.
     
    Walter Wang [MSFT], Aug 3, 2006
    #11
  12. Bill Cohagan

    Bill Cohagan Guest

    Walter
    Thanks. Please let me know what you find out. I'd appreciate it if you
    would email me directly (using the email provided with my alias
    registration). I have submitted feedback as you suggested, referencing this
    newsgroup thread for details.

    Bill
     
    Bill Cohagan, Aug 3, 2006
    #12
  13. Hi Bill,

    I've consulted our product team on this issue.

    The cause of this issue is that child controls use their runtime rendering
    in the designer since they don't even have designers created. Only
    top-level controls have designers and thus have specialized design-time
    rendering.

    For now, do you think following workaround will work for you?

    <table runat="server" id="test2">
    <tr runat="server" id="row2">
    <td id="cell2" runat="server">
    <uc:NewEditDeleteButtons ID="NewEditDeleteButtons2"
    runat="server" />
    </td>
    </tr>
    </table>

    Use this notation, you can still have access to the table/row/cell in
    server-side code.

    Thank you for your feedback, it will certainly help us to make our products
    better!


    Regards,
    Walter Wang (, remove 'online.')
    Microsoft Online Community Support

    ==================================================
    When responding to posts, please "Reply to Group" via your newsreader so
    that others may learn and benefit from your issue.
    ==================================================

    This posting is provided "AS IS" with no warranties, and confers no rights.
     
    Walter Wang [MSFT], Aug 4, 2006
    #13
  14. Bill Cohagan

    Bill Cohagan Guest

    Walter
    Thanks for looking into this. I'm afraid however that I don't understand
    the explanation provided. It seems from what you say that the child controls
    (buttons in my case) should use their runtime rendering in the designer.
    Obviously that's not happening. As for the "workaround", I believe that's
    exactly the code I'm already using and server side access to the control
    hasn't been a problem. The problem is that it is difficult to layout a web
    form using many of these user controls when they don't appear in the
    designer.

    Does the product team consider this a defect; i.e., something that will be
    fixed in the future? Your response doesn't seem to address this at all. In
    any case, thanks again for following up.

    Regards,
    Bill
     
    Bill Cohagan, Aug 4, 2006
    #14
  15. Hi Bill,

    Thank you for your quick reply.

    I'll do further researching on this issue and will get back to you as soon
    as possible. Thank you for for patience and understanding.

    In my test, the workaround using <table>, <td> rather than <asp:table>,
    <asp:TableCell> correctly renders the UserControl at design-time. Do you
    mean that this workaround didn't render the UserControl either?



    Regards,
    Walter Wang (, remove 'online.')
    Microsoft Online Community Support

    ==================================================
    When responding to posts, please "Reply to Group" via your newsreader so
    that others may learn and benefit from your issue.
    ==================================================

    This posting is provided "AS IS" with no warranties, and confers no rights.
     
    Walter Wang [MSFT], Aug 7, 2006
    #15
  16. Bill Cohagan

    Bill Cohagan Guest

    Walter
    Sorry, I misunderstood your workaround, not noticing the change from
    asp:table to table. I'll give that a try and let you know.

    Bill
     
    Bill Cohagan, Aug 7, 2006
    #16
  17. Bill Cohagan

    Bill Cohagan Guest

    Walter
    I've now tried the workaround. Unfortunately it doesn't work for me
    because the use control itself is being placed within an asp:Tablecell
    element on the page where I'm using it. So simply using the table element
    rather than the asp:table element within the control definition is not
    sufficient in my case. Modifying the code that *uses* the user control is
    not a feasible solution since I have little or no control over that code.

    Please let me know what else you find out about this problem.

    Thanks,
    Bill
     
    Bill Cohagan, Aug 7, 2006
    #17
  18. Hi Bill,

    I've consulted with product team and confirmed this is a limitation of
    Visual Studio 2005. For those who are monitoring this thread, here's the
    summary of this issue:


    Symptom
    =======
    UserControl will not render correctly at design time if it's used inside
    <asp:TableCell> tag.

    Reproduce Steps
    ===============
    1) Create a UserControl, add a <asp:Button>
    2) Use it on a WebForm inside <asp:TableCell> tag:

    <asp:Table ID="table1" runat="server">
    <asp:TableRow ID="row1" runat="server">
    <asp:TableCell ID="cell1" runat="server">
    <uc1:WebUserControl ID="WebUserControl2" runat="server" />
    </asp:TableCell>
    </asp:TableRow>
    </asp:Table>

    3) Switch to design time of the WebForm, the UserControl is not rendered
    correctly.


    Sorry for the inconvenience of this issue. Bill, thank you for your
    feedback. I believe this will help us to make our products much better.



    Regards,
    Walter Wang (, remove 'online.')
    Microsoft Online Community Support

    ==================================================
    When responding to posts, please "Reply to Group" via your newsreader so
    that others may learn and benefit from your issue.
    ==================================================

    This posting is provided "AS IS" with no warranties, and confers no rights.
     
    Walter Wang [MSFT], Aug 9, 2006
    #18
    1. Advertisements

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.