Running same code on differint pages

  • Thread starter Thread starter Morten Snedker
  • Start date Start date
M

Morten Snedker

On the load part of 6 differint aspx pages I wish to run the same
code. Instead of having the same code on 6 pages it would be kind of
nice to have it in one place and include/call it.

How should I do this?

Regards /Snedker
 
On the load part of 6 differint aspx pages I wish to run the same
code. Instead of having the same code on 6 pages it would be kind of
nice to have it in one place and include/call it.

How should I do this?

Create a separate class and put your code in it.
 
Compile an assembly from the command-line,
and reference the dll in any page you want to use it from.

See:
http://msdn.microsoft.com/library/d...s/vblr7/html/vaconbuildingfromcommandline.asp

In short:

You can compile the assemblies manually.

Open a command window ( cmd.exe ) and make sure that the .Net Framework
directory is in your path ( the .Net dir is where the vb and cs compilers are located ) ;
navigate to the directory where you have your .vb files, and run the compile command :

vbc /t:library /out:myFile.dll myFile.vb

myFile.dll will be created/compiled in the current directory.

Move the assembly to the /bin directory of your application and fire away.
If you want to have VS.NET use it, reference it in your project.

If you want to use C#, then the command line would be :

csc /t:library /out:myFile.dll myFile.cs

If you need to import .Net classes, include them in your command line:

vbc /t:library /r:system.dll /r:system.web.dll /out:common.dll common.vb
csc /t:library /r:system.data.dll /r:system.web.dll /out:common.dll common.cs

After you compile the assembly, call it in your .aspx pages with :

<%@ Import Namespace="YourClassName" %>

Now, you can reference your methods ( in the aspx page ) with :

YourClassName.YourMethod



Juan T. Llibre, asp.net MVP
asp.net faq : http://asp.net.do/faq/
foros de asp.net, en español : http://asp.net.do/foros/
===================================
 
Back
Top