RE: inheritance trouble - how to detect run-time or design-time in code
From: Steven Cheng[MSFT] (v-schang_at_online.microsoft.com)
Date: 03/30/04
- Next message: Yiaz: "Simple details View style with 1.1"
- Previous message: Fredrik Ålund: "Re: SqlConnection vs. OdbcConnection?"
- In reply to: PearCZ: "inheritance trouble - how to detect run-time or design-time in code"
- Next in thread: PearCZ: "Re: inheritance trouble - how to detect run-time or design-time in code"
- Messages sorted by: [ date ] [ thread ]
Date: Tue, 30 Mar 2004 08:00:16 GMT
Hi PearCZ,
>From your description, you made a simple base page class and make some
certain pages derived from it. The base class will throw a exception its
construnctor according to some certain configure datas in the web.config
file. However you found that after the first the derived page run and
throws the exception, I'll no longer be able to load the derived page into
VS.NET's design view again, yes?
As for this problem, I've tested following the steps you provided on my
side and did repro the problem you mentioned. In fact, this problem is
because the VS.NET will also run the page at design time(when you double
click the page to show its design) , it'll call the page class's
constructor, OnInit method ...etc. That's why when you closed the design
view window and open it again, you'll get the exception too. And normally,
if the certain code is in Page_Init or Page_Load event, you can use a
certain codeline to detect whether it is design time or runtime so as to
make sure the code only be called at runtime, for example:
Protected Overrides Sub OnInit(ByVal e As EventArgs)
InitializeComponent()
MyBase.OnInit(e)
Dim com As System.ComponentModel.IComponent = CType(Me,
System.ComponentModel.IComponent)
If Not com.Site.DesignMode Then
GetWebConfig()
End If
End Sub 'OnInit
However, as for the Constructor, we're unable to use the above means to
get the mode info. So currently we have the following means to workaround
the problem:
1. When developing the page, we comment the certain code which throws the
exception in the construcutor and uncomment it when deploy them.
2. Move the code into page's OnInit method and use the
Dim com As System.ComponentModel.IComponent = CType(Me,
System.ComponentModel.IComponent)
If Not com.Site.DesignMode Then
GetWebConfig()
End If
To confirm that the certain code(throws exception) only be called at
runtime rather than design time. Please check out the above things, if you
have anything unclear, please feel free to post here. Thanks.
Regards,
Steven Cheng
Microsoft Online Support
Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)
Get Preview at ASP.NET whidbey
http://msdn.microsoft.com/asp.net/whidbey/default.aspx
- Next message: Yiaz: "Simple details View style with 1.1"
- Previous message: Fredrik Ålund: "Re: SqlConnection vs. OdbcConnection?"
- In reply to: PearCZ: "inheritance trouble - how to detect run-time or design-time in code"
- Next in thread: PearCZ: "Re: inheritance trouble - how to detect run-time or design-time in code"
- Messages sorted by: [ date ] [ thread ]
Relevant Pages
|