Call A function from one page to another page in asp.net using c#

Call A function from one page to another page in asp.net using c#

A Folder Named App_Code is created by Visual Studio in our Application by Default.

We have to create a Public Class in that folder.
And then write our function which we want to replicate in multiple pages.

Then :-
In the respective pages simply create the object of that public class, all the objects will be able to access
all the public functions of that class.

In the class (in App_code)

public class themainclass
{
   public void tobereplicatedfuntion()
   {
      // Do Something you want to replicate
}

____________________
In Respective Pages (New object )
themainclass objthemainclass = new themainclass();
objthemainclass.tobereplicatedfuntion();

_________________________________________

 

Lets See Working Example

calling one function in different pages

Social Share

Leave a Reply

Your email address will not be published. Required fields are marked *