Click to See Complete Forum and Search --> : Newbie's Question - ASAP


tenno
May 29th, 2006, 02:28 AM
Sorry for asking a stupid question, i'm new in asp.net. I would like to know how to create a Public Function and call it from any web form? In VB6 or VB.net it suppose coding in Module or Class.
Thanks in advance

Shuja Ali
May 29th, 2006, 05:31 AM
You can add a module to your project and create the function with the public access modifier.

tenno
May 30th, 2006, 03:07 AM
That's my problem, i can't find "Module" anywhere to add into ASP.net when i clicked "add new item", by the way i already try to add in a "Class" and created a public function inside but i can't call it from other web form either...any clue?

Shuja Ali
May 30th, 2006, 03:15 AM
So that means you are using C#, right?

C# does not have modules. If you want your function to be public across your project then you will have to add it to a class and use static modifier in the declaration. This way you can use the method even if there is no instance of the class intantiated. Something like thispublic class commonMethods
{
public static void commonFunction....
{
//code for the function
}
} Now you can call this method directly without creating the instance of the class, like this commonMethods.commonFunction.....

If you are using VB.NET then you should be able to Add a module from Project menu.

tenno
May 30th, 2006, 04:24 AM
Sorry for confusing you, actually i'm using ASP.net with VB Scrip, I would like to create a public function into my ASP.net project...

Shuja Ali
May 30th, 2006, 05:05 AM
Sorry for confusing you, actually i'm using ASP.net with VB Scrip, I would like to create a public function into my ASP.net project...
As I said, if it is VB.NET then you can add a module from Project Menu.

Open Project Menu, select Add New Item and in the resulting dialog box select Module from the right hand side list of items.

tenno
May 30th, 2006, 07:16 AM
Forget about VB.net ok?...i'm talking about ASP.net, it's ASP.net...
i'm very advance in Visual Basic by the way, now i'm learning ASP.net

Shuja Ali
May 30th, 2006, 07:29 AM
Forget about VB.net ok?...i'm talking about ASP.net, it's ASP.net...
i'm very advance in Visual Basic by the way, now i'm learning ASP.net
I know you are very advance in VB.NET. :)

When you talk about ASP.NET you either use VB.NET or C# language to write code.

By the way can you tell me which IDE are you using and what is the version of the framework?

My previous post still holds good if you are using VB.NET for developing ASP.NET application in Visual Studio 2003.

tenno
May 30th, 2006, 08:01 AM
haha ok well...the version i'm using is 2.0 visual studio 2005 and there is no "Module" can be select while click add new item. Only Global class or class...any help?

Shuja Ali
May 30th, 2006, 08:47 AM
See how it helps if you post the version in the first post, there wouldn't have been any need of so many posts.

So now you will use a Class with a shared function like this:Public Class commonMethods
Public Shared Function commonFunction()
'code for the function goes here
End Function

End Class
Does this help?

And just to clear your confusion about ASP.NET and VB.NET/C#. Basically ASP.NET is the term used for web based development tool in which you will either have to use VB.NET/C# to code. So when you are talking about ASP.NET you need to specify which language you are using and what version. It helps a lot in resolving the problems.

tenno
May 30th, 2006, 09:13 AM
Yea I got it, thanks for your help and comment, really thanks a lot...have a nice day and good luck.....

Shuja Ali
May 30th, 2006, 09:27 AM
Yea I got it, thanks for your help and comment, really thanks a lot...have a nice day and good luck.....
You are welcome friend. :)