Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / Visual Studio.NET / Extensibility / March 2008

Tip: Looking for answers? Try searching our database.

VS 2005 Web Designer: Can It Create Custom Page Class?

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Axel Dahmen - 04 Mar 2008 20:02 GMT
Hi,

I've created a page class derived from System.Web.UI.Page and altered the
Render member function to render controls (and the page itself ) in a custom
way.

Unfortunately VS Designer only creates the built-in Page class when
displaying the page in designer view. So I can't use the customed effects in
Designer.

Is it possible to get VS Designer to use the *actual* page class the .aspx
pages' code-behind classes inherit from when displaying the page in Design
view?

TIA,
Axel Dahmen
Wen Yuan Wang [MSFT] - 05 Mar 2008 10:43 GMT
Hello Axel,

I'm not sure I have understood the issue completely. It seems you have a
class which derived from Web.UI.Page. In Designer mode, you want to get
some additional properties (which have been added in your new page class)
in the "Proprieties" windows? Correct? Please don't hesitate to correct me
if I misunderstood anything here.

Have a great day,
Best regards,

Wen Yuan
Microsoft Online Community Support
==================================================
This posting is provided "AS IS" with no warranties, and confers no rights.
Axel Dahmen - 05 Mar 2008 13:20 GMT
Hi Wen Yuan,

thanks for taking the time.

I've created some custom controls. They require a custom property
implemented into my page base class to render correctly.

Here're some sample classes, giving an impression of the idea (following is
just kind of pseudo code):

// -- Page base class, defined in control library ----
class MyPageBase : System.Web.UI.Page
{
 public bool MyProperty { get { return true; } }
}

// -- Some ASPX page, deriving from MyPageBase ----
class MyAspxPage : MyPageBase
{
}

// -- a custom control, put on the above ASPX page ----
class MyControl : System.Web.UI.WebControls.CompositeControl
{
 ...

 protected override void Render(HtmlTextWriter writer)
 {
   ...

   if ( ((MyPageBase)Page).MyProperty == true)
   {
     ...
   }
 }
}

This works at runtime, but unfortunately yet, it doesn't work in Designer
view. VS Designer seems to create the page design view using an original Page
class instead of creating and using my custom page base class.

-------------------

> Hello Axel,
>
[quoted text clipped - 11 lines]
> ==================================================
> This posting is provided "AS IS" with no warranties, and confers no rights.
Wen Yuan Wang [MSFT] - 06 Mar 2008 05:04 GMT
Hello Keentoknow,
Thanks for your reply.

Do you get any error message in designer mode?
Is it "Unable to cast object of type 'System.web.ui.page' to type
'MyPageBase''?

We need to perform more research on this issue.
Please let me know the exact  error message, this will help on research
very much.

Have a great day,
Best regards,

Wen Yuan
Microsoft Online Community Support
==================================================
This posting is provided "AS IS" with no warranties, and confers no rights.
Axel Dahmen - 06 Mar 2008 13:04 GMT
I'm sorry, I forgot to mention this...  You're right, it's "Unable to cast
object of type 'System.web.ui.page' to type 'MyPageBase'."

---------------

> Hello Keentoknow,
> Thanks for your reply.
[quoted text clipped - 14 lines]
> ==================================================
> This posting is provided "AS IS" with no warranties, and confers no rights.
Wen Yuan Wang [MSFT] - 07 Mar 2008 07:14 GMT
Hello Keentoknow,
Thanks for your reply.

I have reproduced the issue. In design mode, there is no Web server, no
http request or http context. Thereby, it's not possible for your custom
control to get its parent page instance which exists in runtime. For this
reason, VS IDE creates default Page instance in designer mode. VS IDE
doesn't know your custom control hosted in page which derives from
MyPageBase class. This resulted the error message "Cannot cast object to
type 'MyPageBase'". But in runtime, asp.net runtime can get all the
information from http context. Thus, the new control works perfect.

For the above reason, I'm afraid to say there is no way to get MyProperty
of MyPagebase instance in Custom Web Control's render method at designer
time. In general, what we do is to generate some static information html
content in designer mode. You can check DesignMode property. The value is
true means it's in design mode. On the other side, the false value means
it's in runtime.

if (this.DesignMode == true)
{
output.Write("this design time property");
}
else
{
if (((MyPageBase)this.Page).MyProperty == true)
  output.Write("this MyPagebase property");
}

Another way is that you may create a ControlDesigner class for extend the
design-mode behavior of a Web server control
http://msdn2.microsoft.com/en-us/library/system.web.ui.design.controldesigne
r(VS.80).aspx
[ControlDesigner Class]

Hope this helps. Please feel free to let me know if there is anything
unclear. We are glad to assist you.

Have a great day,
Best regards,

Wen Yuan
Delighting our customers is our #1 priority. We welcome your comments and
suggestions about how we can improve the support we provide to you. Please
feel free to let my manager know what you think of the level of service
provided. You can send feedback directly to my manager at:
msdnmg@microsoft.com.
=================================================
This posting is provided "AS IS" with no warranties, and confers no rights.
Axel Dahmen - 10 Mar 2008 20:06 GMT
Hi Wen Yuan,

that's bad... A designer solution is not sufficient.

I need to have access the the pages' and controls' base classes. I've
created a master page concept which is slightly more flexible than the
Microsoft one. I'd originally invented it for 1.1 and here at the bank we
have decided to use it due to drawbacks of the Microsoft concept. But I
cannot get the Designer to display it because Designer doesn't trigger the
Page/Masterpage rendering interaction... A designer class couldn't cope with
this, I guess.

I don't understand why the page can not be created by VS when the page is
opened in Designer mode. The ASPX part is available and right in the first
line it says which class to instantiate....

What would you suggest? Is there a way to have my pages get a custom
rendering in Designer? (Not a static one..)

TIA,
Axel Dahmen

> Hello Keentoknow,
> Thanks for your reply.
[quoted text clipped - 45 lines]
> =================================================
> This posting is provided "AS IS" with no warranties, and confers no rights.
Wen Yuan Wang [MSFT] - 11 Mar 2008 12:28 GMT
Hello Axel,
Thanks for your reply.

It seems the issue is different from the previous one. I'm not sure about
what do you mean by "Designer doesn't trigger the Page/Masterpage rendering
interaction...". I'm not sure what kind of custom rendering you are looking
for in Designer, either. Could you please provide more information?

Actually, you really can get information of the current control in Render
method. But you cannot get information about its parent control. I'm sorry
to say designer mode is not enough smart to know anything when in runtime.
This is product limitation. Many controls released by Microsoft also use
the Static Information in Designer mode. This shouldn't be the matter in
your application, because these controls work fine in running.

Hope this helps. Let me know if you have any more concern. I'm glad to
assist you.
Best regards,
Wen Yuan

Delighting our customers is our #1 priority. We welcome your comments and
suggestions about how we can improve the support we provide to you. Please
feel free to let my manager know what you think of the level of service
provided. You can send feedback directly to my manager at:
msdnmg@microsoft.com.
==================================================
This posting is provided "AS IS" with no warranties, and confers no rights.
Axel Dahmen - 11 Mar 2008 17:07 GMT
Hi Wen Yuan,

thanks again for staying with this topic.

On my page class there is a custom rendering interaction implemented to
facilitate the master page concept. For this I need to call a custom
MyPage.Render() method which itself adresses the Controls collection.

You have a point in that I could create a static Render method and provide
all necessary arguments as parameters. This might be a good idea you have...
Although, from a software engineering point of view, this isn't OOD at all.
So it's just a workaround. But it'll do the job.

I still don't understand why the IDE doesn't just call the ASPX pages'
constructor. There's even this new DesignMode property being invented to tell
if a page is shown by VS Designer...

Perhaps I should add a suggestion to Connect... But, still, for now your
workaround is quite feasible.

Your help has been quite appreciated!
Axel

------------

> Hello Axel,
> Thanks for your reply.
[quoted text clipped - 23 lines]
> ==================================================
> This posting is provided "AS IS" with no warranties, and confers no rights.
Wen Yuan Wang [MSFT] - 13 Mar 2008 04:37 GMT
Hello Axel,

Thanks for your reply. I understood your scenario. In your master page
concept, the page derived from master page need to call base page's render
method which addresses the controls collection. This way could work fine in
run time. But we lose the support in VS IDE Webpage Designer. I'm sorry,
but VS IDE always create "Page" instance as the base class. This is VS IDE
Web Designer limitation. We cannot change this behavior.

I have submitted this suggestion in our DB for Visual Studio product team
to investigate. If you really have concern on this and want to communicate
with VS product team developer on this it directly, you can also consider
submitting a suggestion to Connect Feedback Portal.
Improving the quality of our products and services is a never ending
process for Microsoft .

Hope this helps. Please feel free to let me know if there is anything we
can help with. We are glad to assist you.
Have a great day,
Best regards,

Wen Yuan
Delighting our customers is our #1 priority. We welcome your comments and
suggestions about how we can improve the support we provide to you. Please
feel free to let my manager know what you think of the level of service
provided. You can send feedback directly to my manager at:
msdnmg@microsoft.com.
==================================================
This posting is provided "AS IS" with no warranties, and confers no rights.

Rate this thread:







Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.