473,803 Members | 2,949 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 1883
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.CShar p.CSharpCodePro vider

Also see...

http://msdn.microsoft.com/library/de...us/cpref/html/
frlrfmicrosoftc sharpcsharpcode providerclassto pic.asp

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

/// M

"Chinmay" <Ch*****@discus sions.microsoft .com> wrote in message
news:68******** *************** ***********@mic rosoft.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.For matMoney( amount );

HTH,

bill

"Neil Zanella" <nz******@gmail .com> wrote in message
news:1a******** *************** ***@posting.goo gle.com...
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
3324
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 ('LOGGED_IN', FALSE );
2
5488
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, produce a "function not defined" message when the SELECT statement is executed, even having previously worked on that machine. What can I do to correct this difficulty when it occurs? What do I need to know about user-defined functions in SELECT...
1
1160
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, while typing out the function call (say objUtility.Func1(args) ), there is a tooltip that appears in VS that shows the arguments....i want some help/descrption also of the arguments to be displayed in this tooltip. What should I do? Is there some...
3
2796
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 IDs. Thanks Vivek
3
3742
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 from aspx form (i.e., code mixed in with html elements) or even call public shared functions from other code behind classes)?
2
1792
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 my plan is to create an assembly CommonFunctions.dll place it in the /bin folder for the application and import the namespace into the code behind where required. Here is an abstract of CommonFunctions.vb
1
1325
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 party software ie functions, headers, libs and put them in a dll. I recently moved the main functions, the libs, and the includes out of the exe and into the dll. I am using loadlibrary to load the dll into memory and I am using getprocaddress to...
0
1000
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 = ADPDS.Utility.Utility.DBNullToDate(null); public DateTime CallbackTime { set{ if(ADPDS.Utility.Utility.IsNullDate(value) == true) _callbackTime = ADPDS.Utility.Utility.DBNullToDate(null); else
3
1504
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 advertised in the library header files are actually defined inside the library. I could imagine a utility which processes the header files and spits out a piece of code which takes the address of each declared function. Missing definitions would then show...
0
9703
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10555
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10317
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10300
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
1
7607
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6844
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5503
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 last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
4277
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 we have to send another system
2
3802
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.