473,386 Members | 1,752 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,386 software developers and data experts.

simple namespace question

I have a method that takes a string, formats it and returns it
I want to use this in multiple ASP.NET pages, by putting it in a namespace and using that in each asp.net page

What I don't understand is how to write that namespace so that I can reference that method elsewhere by simply writing
string Message = "Hello world";
string newstring = MyNamespace.MyMethod(Message)

so I can call the method without having to create a new objec

Thankyou, Katie.
Nov 18 '05 #1
3 1095
You are talking about static(shared in vb.net) method which allow to execute
method without need in object been created.
example:

class MyClass
{
string static MyMethod(string Input)
{
....
return ...;
}
}

using:
string Message = "...";
string newstring = MyClass.MyMethod(Message);
HTH

"Katie S" <an*******@discussions.microsoft.com> wrote in message
news:82**********************************@microsof t.com...
I have a method that takes a string, formats it and returns it.
I want to use this in multiple ASP.NET pages, by putting it in a namespace and using that in each asp.net page.
What I don't understand is how to write that namespace so that I can reference that method elsewhere by simply writing : string Message = "Hello world";
string newstring = MyNamespace.MyMethod(Message);

so I can call the method without having to create a new object

Thankyou, Katie.

Nov 18 '05 #2
Mmhh i am very puzzled by your question as it seems you speak about 2
totally different things.

If you want to import a namespace in your aspx page, at the top just put
something like :

<%@ Import namespace="MyNameSpace" %>

But if you want to do :
"so I can call the method without having to create a new object "
as you say in your message, then the method need to be static (shared in VB)

You will call that method like :
Myclass.MyMethod();

No need to specify the full namespace as you can import it as i showed you.

Best regards,

Francois
"Katie S" <an*******@discussions.microsoft.com> wrote in message
news:82**********************************@microsof t.com...
I have a method that takes a string, formats it and returns it.
I want to use this in multiple ASP.NET pages, by putting it in a namespace and using that in each asp.net page.
What I don't understand is how to write that namespace so that I can reference that method elsewhere by simply writing : string Message = "Hello world";
string newstring = MyNamespace.MyMethod(Message);

so I can call the method without having to create a new object

Thankyou, Katie.

Nov 18 '05 #3
Hi Katie,

Namespaces have no methods, they are only a way to easily identify
classes and avoid collision between classes name. Instead you could
create a class with a static method so, when you want to use it, you
don't have to create an instance of it.

HTH,

Stefano Mostarda MCP
Rome Italy

Katie S wrote:
I have a method that takes a string, formats it and returns it.
I want to use this in multiple ASP.NET pages, by putting it in a namespace and using that in each asp.net page.

What I don't understand is how to write that namespace so that I can reference that method elsewhere by simply writing :
string Message = "Hello world";
string newstring = MyNamespace.MyMethod(Message);

so I can call the method without having to create a new object

Thankyou, Katie.

Nov 18 '05 #4

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

Similar topics

22
by: lokman | last post by:
Hi, In the following code, can someone tell me the difference between *p++ and p++ ? I can see both achieve the same result. Thanks a lot !
7
by: Mark Prenter | last post by:
Hi all, I'm fairly new to .NET and I haven't done much in C++ before, nothing complex anyway, but I have a pretty good understanding of programming in general. What I'm trying to do is create a...
2
by: Hazzard | last post by:
I just realized that the code I inherited is using all asp.net server controls (ie. webform controls) and when I try to update textboxes on the client side, I lose the new value of the textbox when...
7
by: SL | last post by:
Could someone direct to a simple explanation of how to use MS Visual Studio 2003 to design .aspx code? This code works if pasted into notepad and run as an .aspx file: <%@ Import...
6
by: Paul | last post by:
Hi All, Framework 1.1 listbox control unable to DataBind I've been googling for an answer to this query that appears quite a lot, but none, it seem, answers my problem directly. I am...
3
by: Marco T. | last post by:
Hi all, why the former code fragment works and the latter doesn't? ============= //CORRECT CODE: namespace ciao { class A{};
3
by: Chrism2671 | last post by:
I'm new to XSLT/XML and I have a very simple, quick question. i've been trying to convert simple xml files into CSV files and have made a simple XSLT template using the w3 tutorials, but it doesn't...
3
by: Steven Edison | last post by:
I have a split container on my form, from within one of them I wish to reach the main from of the app. I'm having problems with the headers and namespaces. I want something like this: ...
4
by: =?Utf-8?B?SmFtZXMgUGFnZQ==?= | last post by:
Am i missing somthing simple? I can't access any of the profile names in my code behind i.e; textBox1.text = Profile.test = "some text" here's the web.config: <?xml version="1.0"?> ...
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
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
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...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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...

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.