How to use the same function in more than one page

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • hime
    New Member
    • Oct 2006
    • 13

    How to use the same function in more than one page

    Hello all,

    I m developing a web page in .Net using C# and many pages use the same functions I don't wont to write the same function in every page is there a way to write the function in one page and call it from all other pages as needed.

    I am not sure if it is only by macking the function public or is there some other way
  • Sandeep akhare
    New Member
    • May 2006
    • 29

    #2
    You can do that
    Simplest way is that create a class which will have all common function
    make those function as static so need to create the object every time :)

    Comment

    • hime
      New Member
      • Oct 2006
      • 13

      #3
      hi

      Actually I don't know what should I use to be able to use the fun. in the new page and should I write the fun. in a web form page. again for using the class
      should I use a code like this?

      using pagename.classn ame;

      and then I can call the fun. excuse me if the is not suppose to be asked??

      Comment

      • Sandeep akhare
        New Member
        • May 2006
        • 29

        #4
        No Yar
        You are asking very basic questions Dude do one thing add new only .cs file
        give a proper name to the class and write all functions as static
        When you want to call these functions call from your page.cs file like
        classname.funct ionname only Simple Dudde try to do much programming
        Best Luck

        Comment

        • hime
          New Member
          • Oct 2006
          • 13

          #5
          Originally posted by Sandeep akhare
          No Yar
          You are asking very basic questions Dude do one thing add new only .cs file
          give a proper name to the class and write all functions as static
          When you want to call these functions call from your page.cs file like
          classname.funct ionname only Simple Dudde try to do much programming
          Best Luck

          thanx dude ya got me i am nubbe at this ;-| am learning and programming at the same time so .... that is it .... thanx again

          Comment

          • nmsreddi
            Contributor
            • Jul 2006
            • 366

            #6
            Hello

            This is nothing but the way of using some oops concepts.

            If you want to use the same function in many form with out writing the code ,then just make a class what ever the functions you want to again ,just write all those functions in that class file .where ever you want to use that function ,just create an object of that class file (in which the function is located)
            just use that object you can get all the functions in that class file

            for example:

            //lets class name be classmain in which all your functions exists

            //let your form name be form1

            where ever you want to use that functions just create object of class like this

            classmain objclass=new classmain();

            now you can use your objclass in your as many times as needed just by having a dot

            objclass.

            you will get all the public methods and variables of that class.

            Hope you will get the best

            Regards

            Nmsreddi

            Comment

            Working...