[211] [ASP.NET] Doesn't recognize the container type in a templated control

Hi,

Here's a couple of problems with the error detection in .ascx and .aspx
files, related to custom templated controls. Probably tricky to fix, but who
knows :)

First, a little background.

Let's take a sample templated control. It appears in a .ascx/aspx file as
follows :
...some HTML......some more HTML... more of the same ]]>

- MyCustomControl derives from System.Web.UI.Control, with the ParseChildren
attribute set to true. ReSharper recognizes it without problems.

- CustomTemplate1 and CustomTemplate2 are get/set public properties with the
type ITemplate.

- The TemplateContainer attribute is applied to both properties to indicates
the container's class.

- Container refers to the container (ok, that was dumb :), and when the
TemplateContainer is used, there is no need to go through the (lousy)
DataBinder.Eval syntax. You can simply access the properties/methods of the
corresponding control. Much easier, no late-binding.


Now the problems.

First :
ReSharper doesn't refer to the TemplateContainer attribute to determine the
class of the Container property. It doesn't recognize the properties/methods
called on it and only suggests adding an Import directive for
System.ComponentModel to use the Container class inside. This directive
doesn't change anything other than 'solving' the error (and displaying
errors for each use of a property/method afterwards).
It would be nice if the type of Container was correctly resolved. In that
case, the error detection in ReSharper could be really useful. Currently...
not so much.


That was the simple one. The other is a bit more devious, and mainly for fun
:)

I'll try to explain the situation.

I have several 'delimiter' controls, with two templates, True and False.
Depending on a condition determined by the code, the contents of only one of
the templates are displayed (I found it much more convenient and readable
than using PlaceHolders and settings their visibilities :).
All of these controls are deriving from the same base class. The derived
classes only need to define the condition itself.

Up to now, it looks like a simple templated control. But that would be too
simple.
With a standard templated control, refers to the Control object 'around' the template. In the case of those delimiters, it would not be of much use. For example : some admin-only info ]]>

Here, Container.UserId must refer to ItemTemplate's container. The delimiter
has to be transparent.
In order to do that, it cannot be a 'simple' templated control using the
ParseChildren attribute.
Instead, the delimiter base class makes use of the ControlBuilder attribute
to specify a custom builder that will look at the tag names inside
(True/False), and add custom (dummy) controls in their place. That way, the
delimiter control can remove one or the other part based on the condition,
and Container still refers to the parent control.

That's it for the background. Now, for ReSharper :)

Sometimes, RS displays an error for True, False, or both. Error indicated :
"Cannot resolve symbol 'True'" (or 'False' :)

It seems to be pretty much random. Both can be recognized, or just one, or
none. If the same control is used multiple times in a .ascx/.aspx, the first
one can have True/False recognized and the second one only False.


Now it's not annoying or anything, but I thought I'd give you something to
play with if you're ever bored :)
In fact, I don't even know how RS manages to recognize any of the
'templates' since they're only used inside the control builder, in string
form. It should consider them just like HTML tags.



Anyway, there it is. The first problem /is/ a bit annoying and finding the
correct type for Container would be very useful. The second problem, as I
said in the beginning, is mainly for fun :)

And yes, I know, it's not the usual ASP.NET "drag this and click that"
method, but it's still ASP.NET. There are many nice things to do other than
putting up one webform, some controls and juggling events :)


Lionel


1 comment
Comment actions Permalink

Lionel,

This feature is not implemented still (You can find a corresponding request
in the tracker) due to absence of some API functions in our PSI. We expect
start using new caches by the end of the week, after that, the API needed to
implement the feature will be available.

--
Sergey V. Coox
JetBrains, Inc
http://www.jetbrains.com
"Develop with pleasure!"


0

Please sign in to leave a comment.