Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Web Development
  3. ASP.NET
  4. How do I call a public function in another page???

How do I call a public function in another page???

Scheduled Pinned Locked Moved ASP.NET
questioncsharp
4 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • C Offline
    C Offline
    code frog 0
    wrote on last edited by
    #1

    Using C# how do I access another page within the project and call a function that is public to it? Do I simply declare a variable as that page name and invoke the function on the variable? Does that work even if the page has already been loaded? I guess I'm wondering if I have to use a FindPage() or something in order to get the instance of the page that has already been displayed... I suppose I could just check in the Page_Load for a QueryString and if it's there have the page call the function on it's own but that seems to be harder than it should be...

    S M 2 Replies Last reply
    0
    • C code frog 0

      Using C# how do I access another page within the project and call a function that is public to it? Do I simply declare a variable as that page name and invoke the function on the variable? Does that work even if the page has already been loaded? I guess I'm wondering if I have to use a FindPage() or something in order to get the instance of the page that has already been displayed... I suppose I could just check in the Page_Load for a QueryString and if it's there have the page call the function on it's own but that seems to be harder than it should be...

      S Offline
      S Offline
      Sreekumar P P
      wrote on last edited by
      #2

      it is simple class call. Forget that it is a page and access the function as in a seperate class. Page 1 namespace TEST { public class PAGE1 : System.Web.UI.Page { -------------------- private void Page_Load(object sender, System.EventArgs e) { PAGE2 obj = new PAGE2(); Response.Write(obj.test()); -------------------------- ------------------- ----------------- Page 2 namespace TEST { public class PAGE2 : System.Web.UI.Page { ------------------------ --------------------------- public string test () { return "SREE"; } ------------------------ --------------------- Sreekumar PP

      C 1 Reply Last reply
      0
      • S Sreekumar P P

        it is simple class call. Forget that it is a page and access the function as in a seperate class. Page 1 namespace TEST { public class PAGE1 : System.Web.UI.Page { -------------------- private void Page_Load(object sender, System.EventArgs e) { PAGE2 obj = new PAGE2(); Response.Write(obj.test()); -------------------------- ------------------- ----------------- Page 2 namespace TEST { public class PAGE2 : System.Web.UI.Page { ------------------------ --------------------------- public string test () { return "SREE"; } ------------------------ --------------------- Sreekumar PP

        C Offline
        C Offline
        code frog 0
        wrote on last edited by
        #3

        Well that would work fine but the Page name also happens to be a namespace name (not my code, cannot change it) how do I indicate I want an instance of the page not the namespace? Right now the compiler is erroring because it's treating it as the name space.

        1 Reply Last reply
        0
        • C code frog 0

          Using C# how do I access another page within the project and call a function that is public to it? Do I simply declare a variable as that page name and invoke the function on the variable? Does that work even if the page has already been loaded? I guess I'm wondering if I have to use a FindPage() or something in order to get the instance of the page that has already been displayed... I suppose I could just check in the Page_Load for a QueryString and if it's there have the page call the function on it's own but that seems to be harder than it should be...

          M Offline
          M Offline
          minhpc_bk
          wrote on last edited by
          #4

          Hi Rex, When a function in a web page can be reused somewhere else, then IMO that's a good candidate for refactoring, you may put this code in a common class so that you can easily reuse it without having to initialize a new instance of the web page.

          1 Reply Last reply
          0
          Reply
          • Reply as topic
          Log in to reply
          • Oldest to Newest
          • Newest to Oldest
          • Most Votes


          • Login

          • Don't have an account? Register

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • World
          • Users
          • Groups