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. Not able to call .NET function with return value in javascript

Not able to call .NET function with return value in javascript

Scheduled Pinned Locked Moved ASP.NET
csharpjavascripthtmlasp-net
8 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.
  • A Offline
    A Offline
    amittinku
    wrote on last edited by
    #1

    ASP.NET function: public int withparam(int x) { int y; y = x + 10; return y; } HTML button function Button1_onclick() { <% var st = withparam(10); %>; document.write(st); } When i click on button, it says var st could not be found. Please let me know where the syntax is wrong and is this the right way

    N C 2 Replies Last reply
    0
    • A amittinku

      ASP.NET function: public int withparam(int x) { int y; y = x + 10; return y; } HTML button function Button1_onclick() { <% var st = withparam(10); %>; document.write(st); } When i click on button, it says var st could not be found. Please let me know where the syntax is wrong and is this the right way

      N Offline
      N Offline
      Nisha Agrawal
      wrote on last edited by
      #2

      you are getting this error as you have declared variable 'st' in <% %> block, means it is declared server side and you are using it at client side. so declare it at client side and assign value by calling server side method.

      var st;
      st = <% withparam(10) %>;
      document.write(st);

      A 1 Reply Last reply
      0
      • N Nisha Agrawal

        you are getting this error as you have declared variable 'st' in <% %> block, means it is declared server side and you are using it at client side. so declare it at client side and assign value by calling server side method.

        var st;
        st = <% withparam(10) %>;
        document.write(st);

        A Offline
        A Offline
        amittinku
        wrote on last edited by
        #3

        I have applied your code. st = <% withparam(10) %>;->It does not work. Please let me know the solution.

        N A 2 Replies Last reply
        0
        • A amittinku

          I have applied your code. st = <% withparam(10) %>;->It does not work. Please let me know the solution.

          N Offline
          N Offline
          Nisha Agrawal
          wrote on last edited by
          #4

          amittinku wrote:

          It does not work.

          what does mean by this? do u got some error or what?

          1 Reply Last reply
          0
          • A amittinku

            I have applied your code. st = <% withparam(10) %>;->It does not work. Please let me know the solution.

            A Offline
            A Offline
            amittinku
            wrote on last edited by
            #5

            no error as such. It does not return anything, i mean return null.

            N 1 Reply Last reply
            0
            • A amittinku

              no error as such. It does not return anything, i mean return null.

              N Offline
              N Offline
              Nisha Agrawal
              wrote on last edited by
              #6

              Replace the line

              st = <% withparam(10) %>;

              with this

              st = <%= withparam(10) %>;

              it would work surely. i have tested it.

              1 Reply Last reply
              0
              • A amittinku

                ASP.NET function: public int withparam(int x) { int y; y = x + 10; return y; } HTML button function Button1_onclick() { <% var st = withparam(10); %>; document.write(st); } When i click on button, it says var st could not be found. Please let me know where the syntax is wrong and is this the right way

                C Offline
                C Offline
                codelinks
                wrote on last edited by
                #7

                use javascript code for withparam function instead of server side code // JScript File function withparam(x) { var y = x + 10; return y; } function Button1_onclick() { var st = withparam(10); document.write(st); alert(st); } call Button1_onclick in OnClientClick

                winnie

                N 1 Reply Last reply
                0
                • C codelinks

                  use javascript code for withparam function instead of server side code // JScript File function withparam(x) { var y = x + 10; return y; } function Button1_onclick() { var st = withparam(10); document.write(st); alert(st); } call Button1_onclick in OnClientClick

                  winnie

                  N Offline
                  N Offline
                  Nisha Agrawal
                  wrote on last edited by
                  #8

                  Yes, the withparam is the actual function to be called, i mean if we don't need any server side processing then this way would be the best.

                  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