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 can i call C# function Through javascript on aspx page

How can i call C# function Through javascript on aspx page

Scheduled Pinned Locked Moved ASP.NET
helpcsharpjavascriptquestion
8 Posts 6 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.
  • G Offline
    G Offline
    gautamamit8
    wrote on last edited by
    #1

    Hello All I get a problem that i need to call a C# function on aspx page through javascript.but i don't how how I call this one. Any help would be Appreciated Amit Gautam

    S N V 3 Replies Last reply
    0
    • G gautamamit8

      Hello All I get a problem that i need to call a C# function on aspx page through javascript.but i don't how how I call this one. Any help would be Appreciated Amit Gautam

      S Offline
      S Offline
      sarang_k
      wrote on last edited by
      #2

      use your c# functions.....

      G 1 Reply Last reply
      0
      • G gautamamit8

        Hello All I get a problem that i need to call a C# function on aspx page through javascript.but i don't how how I call this one. Any help would be Appreciated Amit Gautam

        N Offline
        N Offline
        N a v a n e e t h
        wrote on last edited by
        #3

        AJAX[^] is the answer. To make things easier, use AJAX toolkit for ASP.NET. :)

        Navaneeth How to use google | Ask smart questions

        G 1 Reply Last reply
        0
        • S sarang_k

          use your c# functions.....

          G Offline
          G Offline
          gautamamit8
          wrote on last edited by
          #4

          I already have my function on mypage.aspx.cs page. I want to call this on aspx page. so how can i do this

          1 Reply Last reply
          0
          • N N a v a n e e t h

            AJAX[^] is the answer. To make things easier, use AJAX toolkit for ASP.NET. :)

            Navaneeth How to use google | Ask smart questions

            G Offline
            G Offline
            gautamamit8
            wrote on last edited by
            #5

            i'm not much aware about Ajax.Could you tellme the any other.I have my function in aspx.cs page I call this on aspx page

            J 1 Reply Last reply
            0
            • G gautamamit8

              i'm not much aware about Ajax.Could you tellme the any other.I have my function in aspx.cs page I call this on aspx page

              J Offline
              J Offline
              J4amieC
              wrote on last edited by
              #6

              What the hell is wrong with you? You ask a question, you're given the de-facto answer and you want a different way of doing it just because you're not familiar. How do you think people learn new concepts?

              1 Reply Last reply
              0
              • G gautamamit8

                Hello All I get a problem that i need to call a C# function on aspx page through javascript.but i don't how how I call this one. Any help would be Appreciated Amit Gautam

                V Offline
                V Offline
                vaghelabhavesh
                wrote on last edited by
                #7

                I would prefer you to use AJAX but here is one other solution. From javascript make a call to dopostback method with eventtarget and arguments (if reuqired) and in Page Load method check for the event target and call the C# method. Remember this is dirty trick. JavaScript (JS File)

                __doPostBack('CALL_MY_METHID','');

                ASPX Code Behind

                void Page_Load(object sender, EventArgs e)
                {
                ....
                ....

                // Insure that the __doPostBack() JavaScript method is created...
                this.GetPostBackEventReference(this, string.Empty);

                string eventTarget = (this.Request["__EVENTTARGET"] == null) ? string.Empty : this.Request["__EVENTTARGET"];
                if (eventTarget == "CALL_MY_METHID")
                {
                // Call your C# method here and return
                CallMyMethod();
                return;
                }
                ....
                ....
                }

                Be careful, there is no Undo Button(Ctrl+Z) in life.

                R 1 Reply Last reply
                0
                • V vaghelabhavesh

                  I would prefer you to use AJAX but here is one other solution. From javascript make a call to dopostback method with eventtarget and arguments (if reuqired) and in Page Load method check for the event target and call the C# method. Remember this is dirty trick. JavaScript (JS File)

                  __doPostBack('CALL_MY_METHID','');

                  ASPX Code Behind

                  void Page_Load(object sender, EventArgs e)
                  {
                  ....
                  ....

                  // Insure that the __doPostBack() JavaScript method is created...
                  this.GetPostBackEventReference(this, string.Empty);

                  string eventTarget = (this.Request["__EVENTTARGET"] == null) ? string.Empty : this.Request["__EVENTTARGET"];
                  if (eventTarget == "CALL_MY_METHID")
                  {
                  // Call your C# method here and return
                  CallMyMethod();
                  return;
                  }
                  ....
                  ....
                  }

                  Be careful, there is no Undo Button(Ctrl+Z) in life.

                  R Offline
                  R Offline
                  Ranjit Viswakumar
                  wrote on last edited by
                  #8

                  .NET is parsed by the server. Javascript is parsed by the browser. If you have page that is already loaded that you want to process a .NET page, asking the server to do so via Javascript is the best way. Ranjit Viswakumar Professional Services Specialist HostMySite.com[^]

                  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