Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > accessing user defined utility functions

Reply
Thread Tools

accessing user defined utility functions

 
 
Neil Zanella
Guest
Posts: n/a
 
      01-18-2005
Hello,

I need to access some user defined utility functions from within
my ASP.NET pages. I wonder whether there is a way to do this. I
do not want to use inheritance. I just want to be able to call
some code contained in a .cs file (C# file) from within several
..aspx and .ascx page without having to rewrite the code in each
such page. I would like to know how this can be accomplished,
including how I can ensure that ASP.NET will find the C#
source file.

Thanks,

Neil
 
Reply With Quote
 
 
 
 
=?Utf-8?B?Q2hpbm1heQ==?=
Guest
Posts: n/a
 
      01-18-2005
ASP.Net won't go and look for .cs files.... when you compile your project
you'll get a DLL and that DLL will be used for all the functinalities not the
..cs. Morover, you can make a Custom Class in your project and add the code
you want to call in every page. than create objects of that class and you are
done!
 
Reply With Quote
 
 
 
 
MWells
Guest
Posts: n/a
 
      01-18-2005
By user-defined, I'm guessing you mean that your website user provides some
C# source to work with. There actually is a way to compile cs at runtime;
though it's not an ASP.NET specific feature.

You'll probably want to provide your users with some kind of
code-upload-and-maintenance UIs, and store the content in a database. One
way or another, you need to get the cs code to your webserver in order to
run it.

For on-the-fly source compilation and execution, google;

Microsoft.CSharp.CSharpCodeProvider

Also see...

http://msdn.microsoft.com/library/de...us/cpref/html/
frlrfmicrosoftcsharpcsharpcodeproviderclasstopic.a sp

http://www.codeproject.com/csharp/RuntimeCompiling.asp

/// M

"Chinmay" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> ASP.Net won't go and look for .cs files.... when you compile your project
> you'll get a DLL and that DLL will be used for all the functinalities not

the
> .cs. Morover, you can make a Custom Class in your project and add the code
> you want to call in every page. than create objects of that class and you

are
> done!



 
Reply With Quote
 
William F. Robertson, Jr.
Guest
Posts: n/a
 
      01-18-2005
You will need to add a seperate code file for this code.

Example:

Add a class file "StringUtils.cs".

//sealed keeps anything from deriving from this
public sealed class StringUtils
{
public static string FormatMoney( decimal amount )
{
//return custom formatting of the amount
}
//private keeps the class from being instantiated.
private StringUtils() { }
}

Now in all your pages in the project you can access this

lblAmount.Text = StringUtils.FormatMoney( amount );

HTH,

bill

"Neil Zanella" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed) om...
> Hello,
>
> I need to access some user defined utility functions from within
> my ASP.NET pages. I wonder whether there is a way to do this. I
> do not want to use inheritance. I just want to be able to call
> some code contained in a .cs file (C# file) from within several
> .aspx and .ascx page without having to rewrite the code in each
> such page. I would like to know how this can be accomplished,
> including how I can ensure that ASP.NET will find the C#
> source file.
>
> Thanks,
>
> Neil



 
Reply With Quote
 
nzanella@cs.mun.ca
Guest
Posts: n/a
 
      01-20-2005
Thank you for your reply,

I have tried your suggestion and received the following
compilation error, which makes me think there is
something else I should specify:

Compiler Error Message: CS0246: The type or namespace name
'StringUtils' could not be found (are you missing a using directive or
an assembly reference?)

Please note that I am not using Visual Studio and am hand
coding the files by hand. I would be very thankful if someone
please let me know what I should do to get rid of this
compilation error.

Thanks,

Neil

 
Reply With Quote
 
nzanella@cs.mun.ca
Guest
Posts: n/a
 
      01-23-2005

Here is how I solved the problem:
<%@ Assembly Src="foo.inc" %>

Regards,

Neil

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
User-defined exception: "global name 'TestRunError' is not defined" jmike@alum.mit.edu Python 1 07-10-2008 12:37 PM
Utility to verify that all declared functions are defined Paavo Helde C++ 3 05-22-2007 06:58 PM
HTML in XSL User-Defined Functions mySpamB8@gmail.com XML 5 06-10-2006 08:41 PM
#if (defined(__STDC__) && !defined(NO_PROTOTYPE)) || defined(__cplusplus) Oodini C Programming 1 09-27-2005 07:58 PM
Accessing functions defined in Global.asax Anjali Lourda ASP .Net 3 02-04-2004 02:50 PM



Advertisments