473,395 Members | 1,504 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

accessing user defined utility functions

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
Nov 19 '05 #1
5 1856
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!
Nov 19 '05 #2
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" <Ch*****@discussions.microsoft.com> wrote in message
news:68**********************************@microsof t.com...
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!

Nov 19 '05 #3
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" <nz******@gmail.com> wrote in message
news:1a**************************@posting.google.c 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

Nov 19 '05 #4
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

Nov 19 '05 #5

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

Regards,

Neil

Nov 19 '05 #6

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

Similar topics

2
by: |-|erc | last post by:
OK, here's the start of the index file I'm working on and its used for every page like so index.php?action=register index.php?action=logout etc. <?php define ('IN_SITE', 1 ); define...
2
by: David Emme | last post by:
Access 97 I have a number of SELECT statements which contain references to user-defined VBA functions. These typically work as expected, but occasionally, on one user's machine or another,...
1
by: Sinex | last post by:
Hi, I have a main application (WinForms). I developed a DLL with some utility classes. The App uses these Utility classes...creates objects of them and then calls their public functions. Now,...
3
by: Vivek Sharma | last post by:
Hi, I have created a dropdownlist as a web user control. I am using its multiple instances on the webpage. How do I access the selectedValue of each instance? All the instances have different...
3
by: CW | last post by:
I find it necessary to mix code-behind and non-code behind techniques sometimes. I have utility functions defined in a VB module. Is there anyway for me to call functions defined in VB module...
2
by: shaun duke | last post by:
I have been researching this over the last two days without success. I have a number of ultility functions that I want to make available to all pages. The pages will all be using code behind so...
1
by: readytoride39 | last post by:
First of all I apologize in advance if this topic does not exactly fit but if someone could still address it I would appreciate it. My boss tasked me to take out all references of this third...
0
by: Alex | last post by:
I have a web service in which I declare a user defined object. One of the properties, I declare it and default it's value as follows: private DateTime _callbackTime =...
3
by: Paavo Helde | last post by:
C++ lets you declare functions in headers which are actually not defined in the source code. During a cleanup cycle for a library I would like to ensure that all free and member functions...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
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...
0
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
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

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.