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 ::
[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.
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.
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.
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.
pure.krome
Member
532 Points
349 Posts
Html.RenderUserControl vs Html.RenderUserControl<T> ?
Mar 12, 2008 01:47 AM|LINK
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.
pure.krome
Member
532 Points
349 Posts
Re: Html.RenderUserControl vs Html.RenderUserControl<T> ?
Mar 13, 2008 10:12 PM|LINK
*polite bump* :)
SteveSanders...
Member
432 Points
119 Posts
Microsoft
Re: Html.RenderUserControl vs Html.RenderUserControl<T> ?
Mar 17, 2008 10:39 AM|LINK
[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.
http://blog.codeville.net/
pure.krome
Member
532 Points
349 Posts
Re: Html.RenderUserControl vs Html.RenderUserControl<T> ?
Mar 18, 2008 06:25 AM|LINK
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?
SteveSanders...
Member
432 Points
119 Posts
Microsoft
Re: Html.RenderUserControl vs Html.RenderUserControl<T> ?
Mar 18, 2008 08:30 AM|LINK
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.
http://blog.codeville.net/
andyfreestyl...
Member
171 Points
56 Posts
Re: Html.RenderUserControl vs Html.RenderUserControl<T> ?
Mar 18, 2008 09:27 AM|LINK
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.
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.
robconery
Participant
852 Points
195 Posts
Re: Html.RenderUserControl vs Html.RenderUserControl<T> ?
Mar 18, 2008 06:46 PM|LINK
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
pure.krome
Member
532 Points
349 Posts
Re: Html.RenderUserControl vs Html.RenderUserControl<T> ?
Mar 19, 2008 01:22 AM|LINK
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 :)