Hi,
I have no any fresh idea, MSDN keeps silence, there is no official way to include some external text files to be compiled as a part of a source code.
I just notice one thing - if you already included some USING namespace in your class and later you included this class into your next file all namespaces included before are accessible.
Dmitri.
One common use of include I am looking for including file with using statements. Typically in a big C# program I have to write around 15-20 using statements on the top every file.
like-
using System;
using System.Windows.Forms;
using System.Drawing;
using blah blah blah
If I put these using statement in a single C# file and include in every C# file. Life will be cool. Same problem with Java. Any alternate to this problem?
--------------------------------------------
Manish Agarwal <
[email protected]>
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]
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.
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]
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.