views:

76

answers:

1

hi,

I want to find out inside a webcontrol the real type of the page that is designed in Visual Studio 2008.

I can obtain the WebFormsRootDesigner, and somehow i know it is possible to get the

file path of the aspx page.

I would like rather to get the ProjectItem for that page, because it would be an overkill to have the control parse the file, but i cannot find a way to do this.

And from the projectitem of an aspx page i have no clue how to get the page class...

I want my webcontrol to behave differently at designtime depending on the page type.

Thanks

+1  A: 

That's a really bad design. It's always bad to have the "inner" behave differently based on the "outer", or the "child" to be based on the "parent".

Instead, have the page tell the control how to behave, by setting a property. Different pages will tell the same control to behave in different ways. This way, if you add a new page, it can still choose to use one of the existing behaviors.

John Saunders
I agree that it is in principle bad design if you control also the page.But let's say i want my control to function in a specific wayon a MVC View Page. It is not the job of the page to say more than it's class. But i do not know how to get to that...
Liviu
Sorry, it _is_ the job of the page to indicate the behavior it wants from the control. Even if all you have is two pages, you would pass a bool to the control to say which behavior to use. Or pass an enum if there's a choice. Don't bind the behavior of the control to the page.
John Saunders
@unknown: You exhibit a common misunderstanding when you suggest you know how the control will be used. Unless you are clairvoyant, you do not. Don't couple the control to how you imagine it will be used, as you will find that your imagination will fail you.
John Saunders
hi john. I think i was not clear about the reason why.Imagine i want my control to get the model type from the typed viewpage loaded in designer.It is supposed to work without out of the box with asp.net mvc.I think I have a valid reason to get to the page.
Liviu
Does the page know the model type? Then let the page tell the control. Simple.
John Saunders