globel method in asp.net

Posted by Seenuvasan under ASP.NET on 6/13/2011 | Points: 10 | Views : 1092 | Status : [Member] | Replies : 6
Hi,

i need to write one globel method.it's name like 'getUserMail()' and want to call this method from my all .cs file(code behind
file)

is it possibile?
how to implement this one?

Thanks,
Seen



Responses

Posted by: Nithadeepak on: 6/13/2011 [Member] Bronze | Points: 25

Up
0
Down
1.create a class library Example and define the function getUserMail() inside a class className . Build the solution to create the dll.

2.In your application, add reference to this dll.

3.in any cs page you can call the function as

using Example;
public partial class class1: System.Web.UI.Page
{
className c=new className();
c.getUserMail();
}



Nitha Deepak

Seenuvasan, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Nithadeepak on: 6/13/2011 [Member] Bronze | Points: 25

Up
0
Down
You can also create a Class under the App_Code folder and in that define common functions that can be called from any pages in your site.

Nitha Deepak

Seenuvasan, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Vuyiswamb on: 6/13/2011 [Member] [MVP] [Administrator] NotApplicable | Points: 25

Up
0
Down
i think is better to create a static class and add a function to do that, so will not be creating an object of that class all the time you need to use it.

Thank you for posting at Dotnetfunda
[Administrator]

Seenuvasan, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Akiii on: 6/13/2011 [Member] Bronze | Points: 25

Up
0
Down
hi,
nitha and Vuyiswamb sir have given you all the hint....

making the class static will eradicate instance making code in every code.....

Thanks and Regards
Akiii

Seenuvasan, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Seenuvasan on: 6/14/2011 [Member] Starter | Points: 25

Up
0
Down
Hi Akiii,

Can u tell me the problem of implementing the static class for above scenario?

Thanks,
Seen

Seenuvasan, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Akiii on: 6/14/2011 [Member] Bronze | Points: 25

Up
0
Down
Hi Seenuvasan...

As per your requirement, declaring a static class will be beneficial as suggested by Vuyiswa sir...
If you declare a static class then you can call any method or a property by just using

Classname.methodname or propertyname 


Otherwise you have make an object of the class and then call the method or the property...like just like nitha has shown you....

public partial class class1: System.Web.UI.Page

{
className c=new className();
c.getUserMail();
}


Please refer a link through which you can understand the concept of static class....

http://www.codeproject.com/KB/cs/codeconcepts.aspx

Let me know if you face any problem....
Thanks and Regards
Akiii


Seenuvasan, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response