Re: Including a file in code behind?

Tech Tip: Click here to run a free scan for Windows Errors and optimize PC performance

From: Mythran (kip_potter_at_hotmail.com)
Date: 08/30/04


Date: Mon, 30 Aug 2004 08:33:01 -0700

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" <mark@gamehostcp.com> wrote in message
news:opsdjw8tzvmmx8vf@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