Html.RenderUserControl vs Html.RenderUserControl<T> ?

Last post 03-18-2008 9:22 PM by pure.krome. 7 replies.

Sort Posts:

  • Html.RenderUserControl vs Html.RenderUserControl<T> ?

    03-11-2008, 9:47 PM
    • Member
      532 point Member
    • pure.krome
    • Member since 05-28-2006, 12:45 AM
    • Melbourne, Australia
    • Posts 348

    Hi folks,
       i've got the following code, which works. 

    <%= Html.RenderUserControl("/views/shared/Membership.ascx") %>

    Ok.. nothing fancy .. some html is rendered to the screen .. kewl. So i tried to do the following...

    <%= Html.RenderUserControl<MyNamespace.BlahBlah.Views.Shared.Membership>(null, null) %> and nothing gets rendered.

     hmm. Why would this be? The first line is the exact same class as the type listed in the < T > section.

    Secondly, the Html.RenderUserControl<T> takes TWO arguments,
    a) object controlData
    b) object propertySettings

    the controlData is any data that the control needs to use, to help it render out. I see that as the view data for that control. If there's no view data, then i can assume i set this as null.
    But what are PropertySettings? I have no idea, so i'm assuming i set that to null.

    :: Never underestimate the predictability of stupidity ::
  • Re: Html.RenderUserControl vs Html.RenderUserControl<T> ?

    03-13-2008, 6:12 PM
    • Member
      532 point Member
    • pure.krome
    • Member since 05-28-2006, 12:45 AM
    • Melbourne, Australia
    • Posts 348

    *polite bump* :)

    :: Never underestimate the predictability of stupidity ::
  • Re: Html.RenderUserControl vs Html.RenderUserControl<T> ?

    03-17-2008, 6:39 AM

    [1] I guess RenderUserControl<T> fails becase it's instantiating the control's code-behind class (not the subclass defined by the ASCX file), so there'll be nothing for it to render. You could argue that it's expected behavior (since you're supplying T=code-behind-class, it's your own fault), but lots of people are going to be confused by this.

    What do others think - would you call it a bug?

     [2] If you supply any values as propertySettings, they'll be applied to any public properties exposed by the control class. Set it to NULL if you don't have any properties you want to set.

  • Re: Html.RenderUserControl vs Html.RenderUserControl<T> ?

    03-18-2008, 2:25 AM
    • Member
      532 point Member
    • pure.krome
    • Member since 05-28-2006, 12:45 AM
    • Melbourne, Australia
    • Posts 348

    I've made sure that the class <T> is the view class by writing out the full namespace :(

     

    has anyone else had any luck with RenderUserControl<T> ?

     

    also, how does RenderUserControl compare to RenderComponent?

    :: Never underestimate the predictability of stupidity ::
  • Re: Html.RenderUserControl vs Html.RenderUserControl<T> ?

    03-18-2008, 4:30 AM

     

    pure.krome:
    I've made sure that the class <T> is the view class by writing out the full namespace :(

    PK, are you sure? It's not a matter of namespace. Do you understand the difference between the code-behind class and the ASCX class that doesn't even exist until in-server compilation?

    If you write RenderUserControl<My.Project.Namespace.MyViewUserControl>(null, null), it's just going to render a blank, because the code-behind class probably doesn't contain any instructions to render anything.

    The only way to make it work is to reference the ASCX class which has a horrible name like RenderUserControl<ASP.views_home_myviewusercontrol_ascx>(null, null).

    I'd suggest the RenderUserControl<T> overload should be removed, because this is just going to cause no end of confusion. I can't think of any way it could be easier to use, given that you can have multiple ASCX files "inheriting" the same code-behind class.

  • Re: Html.RenderUserControl vs Html.RenderUserControl<T> ?

    03-18-2008, 5:27 AM

    SteveSanderson:
    only way to make it work is to reference the ASCX class which has a horrible name like RenderUserControl<ASP.views_home_myviewusercontrol_ascx>(null, null)

    I've yet to test this out, so thanks for this hint, as just like pure.krome I had a couple of blank moments, rendering empty user controls.

    SteveSanderson:
    I'd suggest the RenderUserControl<T> overload should be removed

    Though I really hope some form of strongly typed RenderUserControl method remains.

    This specific issue, I'd really like to see some advice from the MVC team. It is confusing. I'd assumed I'd just got the naming convention wrong for the ascx file in the Shared folder.

  • Re: Html.RenderUserControl vs Html.RenderUserControl<T> ?

    03-18-2008, 2:46 PM
    • Participant
      846 point Participant
    • robconery
    • Member since 02-23-2005, 10:16 PM
    • Posts 192
    • AspNetTeam

    I apologize for the confusion here - this would be my fault, entirely. One of the things I had planned to do was to strip out the typed RenderUserControl since, as you mention, it didn't actually render. It was sloppy on my part and I've just sent Eilon (the lead dev) a note to be sure to remove.

    Again - sorry about the confusion, my fault entirely.


    Rob

  • Re: Html.RenderUserControl vs Html.RenderUserControl<T> ?

    03-18-2008, 9:22 PM
    • Member
      532 point Member
    • pure.krome
    • Member since 05-28-2006, 12:45 AM
    • Melbourne, Australia
    • Posts 348

    Hi guys,

    @StevenSanderson: err.. *blush* i'll need to double check but what your saying does make sence though .. *blush*. Blonde moment (again!)

    @Rob: kewlies.. i'll not use it then if it will be removed from future versions

    @Rob (again ... or anyone else): how does RenderUserControl compare to RenderComponent?

    cheers :)

    :: Never underestimate the predictability of stupidity ::
Page 1 of 1 (8 items)