Wrox Programmer Forums
Go Back   Wrox Programmer Forums > .NET > Other .NET > General .NET
|
General .NET For general discussion of MICROSOFT .NET topics that don't fall within any of the other .NET forum subcategories or .NET language forums.  If your question is specific to a language (C# or Visual Basic) or type of application (Windows Forms or ASP.Net) try an applicable forum category. ** PLEASE BE SPECIFIC WITH YOUR QUESTION ** When posting here, provide details regarding the Microsoft .NET language you are using and/or what type of application (Windows/Web Forms, etc) you are working in, if applicable to the question. This will help others answer the question without having to ask.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the General .NET section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old June 18th, 2004, 03:53 AM
Friend of Wrox
 
Join Date: Jun 2004
Posts: 128
Thanks: 0
Thanked 0 Times in 0 Posts
Default How to write global funcions in C#.net

Actually we have to write a global function so that we access all that function from all the webforms of the same project. If want to call the function from other webforms. And how to write the function in the .cs file. Please send the reply as soon as possible.
 
Old June 18th, 2004, 08:25 AM
planoie's Avatar
Friend of Wrox
 
Join Date: Aug 2003
Posts: 5,407
Thanks: 0
Thanked 16 Times in 16 Posts
Default

Please don't cross post. See this thread.
 
Old June 25th, 2004, 12:17 AM
Friend of Wrox
 
Join Date: Jun 2004
Posts: 449
Thanks: 0
Thanked 1 Time in 1 Post
Send a message via MSN to r_ganesh76
Default

you can do this by writing public static functions. static functions you dont need to instantiate the class. You can call these methods directly using the class.

eg:

using System;

namespace MyNamespace
{
    public class GlobalMethods
    {
        public GlobalMethods()
        {
        }

        public static int Sum (int a, int b)
        {
            return a + b;
        }
    }
}


You can invoke the Sum method of the class in your webforms without declaring the instance of the class

private void Button1_Click(object sender, System.EventArgs e)
{
        TextBox1.Text = Sum(5, 20).ToString();
}

Regards
Ganesh

 
Old June 25th, 2004, 12:19 AM
Friend of Wrox
 
Join Date: Jun 2004
Posts: 449
Thanks: 0
Thanked 1 Time in 1 Post
Send a message via MSN to r_ganesh76
Default

Sorry a mistake in the reply....

the web form should have the following
private void Button1_Click(object sender, System.EventArgs e)
{
        TextBox1.Text = MyNamespace.GlobalMethods.Sum(5, 20).ToString();
}

Regards
Ganesh








Similar Threads
Thread Thread Starter Forum Replies Last Post
Where is Global.aspx for ASP.net 2.0 jdang67 ASP.NET 2.0 Basics 2 June 2nd, 2009 03:40 AM
How to use global dataset for asp.net application swati_joshi ASP.NET 1.0 and 1.1 Basics 3 April 6th, 2007 09:30 PM
Global Variables in ASP.NET mehdi62b ASP.NET 1.0 and 1.1 Professional 11 August 8th, 2004 03:15 AM
Global Variables in .NET mbmsecret C# 5 July 6th, 2004 02:27 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.