473,480 Members | 2,349 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Including a file in code behind?

I have an interesting situation that i could not find a resolution for on
google or msdn, it goes as follows:
The web app i have has about 35 pages, each requires the same code in the
page_load (about 62 lines). If i need to change a single part of that
code, is there a way to do it without find/replace over the whole project.
As the code i wish to change (and other sections i may wish to change in
the future) is also in some other parts of the project. Such as below:

if (helper.GetServiceRunning((string)Session["__SelectedService"]))
{
txtStartStop.Text = "Stop";
divRestartServer.Visible = true;
}
else
{
txtStartStop.Text = "Start";
divRestartServer.Visible = false;
}

I need to add a parameter to helper.GetServiceRunning, i was thinking it
would be mighty handy if i could just put this code in a .cs file and
include it at the right point on every page, then any changes/additions
would be dead easy later on.

I'm using Visual Studio .Net 2003 if it will pre-process anything to do
this.

Any ideas/insights would be very good :)

Its pretty frustrating when you need to go and change something =\
- Mark
Nov 18 '05 #1
2 1496
Sure, create a web user control and put all this code into it. Depending on what
exactly it is you are doing, you may need to put the code into the Initialize
event and not Page_Load. This way, your code is executed prior to the page's
Page_Load event handler.

Hope this helps :)

Mythran
"Mark Harris" <ma**@gamehostcp.com> wrote in message
news:op**************@mark.network.dvmesh.com...
I have an interesting situation that i could not find a resolution for on
google or msdn, it goes as follows:
The web app i have has about 35 pages, each requires the same code in the
page_load (about 62 lines). If i need to change a single part of that
code, is there a way to do it without find/replace over the whole project.
As the code i wish to change (and other sections i may wish to change in
the future) is also in some other parts of the project. Such as below:

if (helper.GetServiceRunning((string)Session["__SelectedService"]))
{
txtStartStop.Text = "Stop";
divRestartServer.Visible = true;
}
else
{
txtStartStop.Text = "Start";
divRestartServer.Visible = false;
}

I need to add a parameter to helper.GetServiceRunning, i was thinking it
would be mighty handy if i could just put this code in a .cs file and
include it at the right point on every page, then any changes/additions
would be dead easy later on.

I'm using Visual Studio .Net 2003 if it will pre-process anything to do
this.

Any ideas/insights would be very good :)

Its pretty frustrating when you need to go and change something =\
- Mark

Nov 18 '05 #2
Thanks for the reply Mythran,

Not quite what i was after as the code hides/shows several parts of the
menu, binds a DropDownList, adds some javascript to the header, sets the
page title, etc. So something more advanced may be needed.

As much as a i now dislike php, one function from it comes to mind: the
Include() function, or C's ability to define a symbol that is then
replaced with the code by the pre-processor.

Again, thankyou for the reply,
- Mark Harris

On Mon, 30 Aug 2004 08:33:01 -0700, Mythran <ki********@hotmail.com> wrote:
Sure, create a web user control and put all this code into it.
Depending on what
exactly it is you are doing, you may need to put the code into the
Initialize
event and not Page_Load. This way, your code is executed prior to the
page's
Page_Load event handler.

Hope this helps :)

Mythran
"Mark Harris" <ma**@gamehostcp.com> wrote in message
news:op**************@mark.network.dvmesh.com...
I have an interesting situation that i could not find a resolution for
on
google or msdn, it goes as follows:
The web app i have has about 35 pages, each requires the same code in
the
page_load (about 62 lines). If i need to change a single part of that
code, is there a way to do it without find/replace over the whole
project.
As the code i wish to change (and other sections i may wish to change in
the future) is also in some other parts of the project. Such as below:

if (helper.GetServiceRunning((string)Session["__SelectedService"]))
{
txtStartStop.Text = "Stop";
divRestartServer.Visible = true;
}
else
{
txtStartStop.Text = "Start";
divRestartServer.Visible = false;
}

I need to add a parameter to helper.GetServiceRunning, i was thinking it
would be mighty handy if i could just put this code in a .cs file and
include it at the right point on every page, then any changes/additions
would be dead easy later on.

I'm using Visual Studio .Net 2003 if it will pre-process anything to do
this.

Any ideas/insights would be very good :)

Its pretty frustrating when you need to go and change something =\
- Mark

Nov 18 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
2833
by: Thomas Connolly | last post by:
I have 2 pages referencing the same codebehind file in my project. Originally the pages referenced separate code behind files. Once I changed the reference to the same file, everything worked...
3
2560
by: Justin | last post by:
I am using asp.net with a C# code behind and I need to figure out how to include a javascript file for use with my code. It was simple to do this in classic ASP: <!-- #include File="md5.js" --> ...
4
1707
by: roger janssens via DotNetMonster.com | last post by:
hello all. i'm used to scripting in php. there, you just include(bla.php) and it works. so i have a template that defines my layout and stays the same forever, but in that file, there's a table...
19
3725
by: Alan Silver | last post by:
Hello, I have been developing ASP.NET with a text editor so far (better way to learn initially), and have now been trying Visual Web Developer. I want to create a project for an existing site...
0
986
by: John Lau | last post by:
Hello, In Asp.Net 1.1, I am using a single code behind file that is shared by multiple Aspx pages and a second shared code behind file for Ascx user controls. The VS 2003 IDE is a bit quirky,...
1
1602
by: archana | last post by:
Hi all, I am confuse regarding concept of code behind model and single file model.. I have heard that single file model compiles dynamically. suppose i have application in which i am having...
3
5953
by: =?Utf-8?B?RGF2ZQ==?= | last post by:
I design all of my pages in expression web. I then want to create a code behind file for the aspx page created by EW in VS 2005. How could I do this easily?
7
1411
by: Shelly | last post by:
Please tell me the best way to do this (I am still new to VB.NET and ASPX) as this should very easy for anyone with any experience to answer. In the code behind file (filename.aspx.vb), I import...
1
2303
by: mirandacascade | last post by:
1) Module1 has the following delcaration: Public g_frmZZZ as Form Public g_txtForm2 as Variant 2) app has two forms: form1 and form2 3) a command button on form1 opens form2; it also has...
0
6911
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7050
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
7091
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
6743
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
2999
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
2988
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1303
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
1
564
muto222
php
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
185
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.