O, yeah, it really helps, thanks a lot!
I think that the question is closed. It's very bad that we can't import an external file as an additional code, but using this inheritance can help to solve this problem.
Dmitri.
"Sorin Dolha [MCSD .NET]" <sd****@hotmail.com> wrote in message news:uA**************@TK2MSFTNGP09.phx.gbl...
It doesn't matter how much code you need to run. And you can use the method I have described even if you have different code on the web pages OnLoad methods by overriding OnLoad twice, once in the MyBasePage (template) class and once in every web page's class, like this:
class MyBasePage : Page
{
public override OnLoad(...)
{
base.OnLoad(); // call the standard Page.OnLoad()
// next, your lines which should execute on every page
}
...
}
// repeat this for every page you currently have in the web site
// basically you will only need to insert "base.OnLoad()" line, and change : Page to : MyBasePage for every web page class
class AWebPage : MyBasePage
{
public override OnLoad(...) // override
{
base.OnLoad(); //calls MyBasePage.OnLoad()
// next, your specific code for this page
}
...
}
I hope it helps,
--
Sorin Dolha [MCAD, MCSD .NET]
"Dmitri Shvetsov" <ds*******@cox.net> wrote in message news:evY0c.12425$id3.8678@fed1read01...
Hi,
You know if it should be a very short code it would be fine, but it's only a part of the code and these few strings should be executed before the rest of the On_Load code that's different for each page and already done. So, I can't just derive the page from my own class. Although it could be a good idea and I will think about it. Maybe in this case we can avoid some extra code and just derive some common part of the code just sending the predefined constants to the constructors. Thanks.
Dmitri.
"Sorin Dolha [MCSD .NET]" <sd****@hotmail.com> wrote in message news:%2****************@tk2msftngp13.phx.gbl...
Dmitri,
Why don't you create a new class (let's call it MyPage) derived from Page, overload the OnLoad() method in MyPage, and then change the base type for every of your web pages' classes to MyPage instead of Page.
This technique is a very common technique for adding common functionality to web pages (it's almost like the master template page concept which will be available in ASP .NET "Whidbey").
--
Sorin Dolha [MCAD, MCSD .NET]
"Dmitri Shvetsov" <ds*******@cox.net> wrote in message news:fWU0c.12379$id3.3055@fed1read01...
Not so easy. I need to do the same steps during ON_LOAD for every asp page.
That's why I need to insert the same strings to compile them in different
classes. If I could use an external file and define a static variables etc.,
it would be a big difference.
Dmitri.
"C# Learner" <cs****@learner.here> wrote in message
news:e6**************@TK2MSFTNGP09.phx.gbl...
Dmitri Shvetsov wrote:
Hi All,
Does somebody know how can I include an external file into my C# source
file?
I need to insert the same strings (about 5-10) into about 75 different
files, probably I will need to modify all these strings later, and I see
it as a good idea to use an INSERT approach, but C# is not C++ and doesn't
allow me just to insert some external file as I used to do. What's a
command for that?
Thanks,
Dmitri.
Create a class in its own file, and add the string constants to it.
e.g.:
public sealed class StringConstants
{
// private constructor to stop it getting instantiated
private StringConstants()
{
}
public const string One = "One";
public const string Two = "Two";
}
Then later you can use StringConstants.One, etc.