views:

171

answers:

6

When I generate code using T4 templates in Visual Studio 2010, I get the following error for each of my asp controls when I try to compile:

Control "ddState" is missing required attribute "showat".

I have never gotten this error in previous versions of .NET. Further, I don't get this error when I manually construct my pages either by dragging/dropping, nor do I get it when I type out the control text myself. When I generate code, I have to manually add showat="client" to my tag for the compiler to be happy. It was my understanding that I never had to explicitly specify this tag. The following:

<asp:dropdownlist id="ddState" runat="server" showat="client" />

solves the problem. Why do I have to add this to generated code but not other times?

(It's a VS-2010 webforms project, using VB, in case that makes a difference.)

+2  A: 

Apparently .NET 5 or another one of those super service packs is going to allow something called targeted rendering. It was originally intended for use just in the context of webforms, but I've heard recently there will be some fancy way to use it in MVC (using some helper classes) and in services using WCF. It will work well with Dynamic Data but is very loosely coupled with it; you can use one or the other completely independently. If you configure your dynamic data with certain tags you can have it constructed on the client, etc.

For now, just put showat="client" in all your tags, and all is good. That's supposed to be the implicit default, but I've heard of cases where the IDE seems to require it. In the future, showat="client" will be the safest setting anyway, giving the expected behavior in 99.9% of cases.

Rice Flour Cookies
I think that's what I'm going to end up doing. In fact, I'm going to do that now so my classes will compile. I'm still hoping someone knows why. For one, I never could get an answer on why an *asp control* needed the `runat` tag. It always annoyed me. So having `showat` annoys me.
Patrick Karcher
+5  A: 

The showat=”client” attribute was always assumed in .NET. The decision has been made to make this explicit for consistency with runat="server". People coming from other frameworks (myself included, coming from java) are thrown off a bit with the inconsistency. Now that it's explicit, things should be more clear. There's also apparently something in the future with .Net services where the showat tag can be used to target output.

What confuses me is this: for backward compatibility, in .NET the showat="client" is supposed to not be explicitly required. I've seen .NET4 working markup that did not have an explicit showat="client". This might be something that works differently in VB and C#. Since you're doing code gen, it should be easy as pie to put it in.

Ocelot20
Thanks, that's good info. Yes, I know I can put it in easily, but it bugs me not knowing *why* I need to.
Patrick Karcher
+2  A: 

This is required in VB, but not C#, which is why it seems to not be necessary sometimes. To be more specific, the C# compiler puts the equivalent of showat=client into the IL automatically, unless you specify a showat target other than client.

But when I constructed pages manually it’s not required. Maybe when you construct with T4 in C# you’d have the same problem. Have you tried that.
Patrick Karcher
No, that’s not the case, because we’ve done that in my shop, using T4 in VS2010 beta. We did not need any tags.
+2  A: 

"showat='client'" should currently have little effect on your coding. It's main purpose is for future WCF output targeting, which they will want to be backward compatible. For now, the only possible value is "client", but in the future there will be other possible values that will allow pre-rendering of cached values, and apparently "pushing" output to services. The example I saw at the last code camp was where you could push to a service at (probably) the same site as well as to the client machine, for logging/debugging purposes. You'd have something like (to use your example):

<asp:dropdownlist id="ddlCP" runat="server" showat="client, logService" />

. . . and then the rendering would go to your log file. Or, to your session provider (if you've got multiple web servers and are implementing a shared session provider), etc. I think logService above would have to be defined in the web.config or something.

ihillVT
That's extremely cool. I can see how it would work well with dynamic data, which I look forward to using. But, would you know why the compiler (the vb compiler at least) requires an explicit statement of the attribute sometimes and not other times?
Patrick Karcher
+1  A: 

Check to see if VB does anything in the web form designer page when you use the IDE to add the control. I'm not sure how VB inserts the implicit tag. But that would be something the T4 template would miss, just a thought...

Chris Anderson
By implicit tag, you mean the `showat` *attribute*, right?
Patrick Karcher
+1  A: 

Agreed that my VS2010 solves this issue for you. Then you can remove the tags completely. I would suggest getting the upgrade. It's well work the $599 upgrade cost. Otherwise, look to add the showat="client" in all the tags. I think that Rising Star got that one right, although I haven't tested it yet.

aeisenbe