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. General Programming
  3. C#
  4. Javascript calling a c# method

Javascript calling a c# method

Scheduled Pinned Locked Moved C#
csharpjavascriptasp-netdatabasesysadmin
6 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
    compninja25
    wrote on last edited by
    #1

    Hi everyone, I have a form on my website and I'm thinking about creating a little javascript function to perform validation. I know asp.net has validation built in, but there are some other things I'd like the function to do that can't be done with the asp.net validation plus it's a learning project. I have a button at the end of the form which I would like to call this javascript function which will validate the form input fields, but then after that I'd like it to call the c# code behind which will access the database and do some other server side functions. Is there a way this can be done? Can you attach two "onClick" event handlers to a single button, or do I have to do something with a "hidden button" that is linked to the codebehind and have the javascript "click" it when it's done? Thanks!

    Knowledge is not power, however, the acquisition and appropriate application of knowledge can make you a very powerful individual.

    A K 2 Replies Last reply
    0
    • C compninja25

      Hi everyone, I have a form on my website and I'm thinking about creating a little javascript function to perform validation. I know asp.net has validation built in, but there are some other things I'd like the function to do that can't be done with the asp.net validation plus it's a learning project. I have a button at the end of the form which I would like to call this javascript function which will validate the form input fields, but then after that I'd like it to call the c# code behind which will access the database and do some other server side functions. Is there a way this can be done? Can you attach two "onClick" event handlers to a single button, or do I have to do something with a "hidden button" that is linked to the codebehind and have the javascript "click" it when it's done? Thanks!

      Knowledge is not power, however, the acquisition and appropriate application of knowledge can make you a very powerful individual.

      A Offline
      A Offline
      Andrew Rissing
      wrote on last edited by
      #2

      What you're talking about doing is having the Javascript force a server side post back event. You might want to start looking at websites such as this[^].

      C 2 Replies Last reply
      0
      • C compninja25

        Hi everyone, I have a form on my website and I'm thinking about creating a little javascript function to perform validation. I know asp.net has validation built in, but there are some other things I'd like the function to do that can't be done with the asp.net validation plus it's a learning project. I have a button at the end of the form which I would like to call this javascript function which will validate the form input fields, but then after that I'd like it to call the c# code behind which will access the database and do some other server side functions. Is there a way this can be done? Can you attach two "onClick" event handlers to a single button, or do I have to do something with a "hidden button" that is linked to the codebehind and have the javascript "click" it when it's done? Thanks!

        Knowledge is not power, however, the acquisition and appropriate application of knowledge can make you a very powerful individual.

        K Offline
        K Offline
        keniagm
        wrote on last edited by
        #3

        First, you must understand that when you write javascript code it runs on client side and your c# code runs on server side. So you can have both, client validation written in javascript by attaching code to the onclick event and server validation written in C#. There's no ambiguity if that's what worries you. Hope this helps.

        Kenia

        C 1 Reply Last reply
        0
        • A Andrew Rissing

          What you're talking about doing is having the Javascript force a server side post back event. You might want to start looking at websites such as this[^].

          C Offline
          C Offline
          compninja25
          wrote on last edited by
          #4

          Ah, that's the ticket! I had a general idea of what I needed the browser to do, but just wasn't sure what it was called. Then I tried googling for "javascript to click a hidden button" or "attaching multiple events to a button" but wasn't getting anywhere. Thank's again for the help!

          Knowledge is not power, however, the acquisition and appropriate application of knowledge can make you a very powerful individual.

          1 Reply Last reply
          0
          • K keniagm

            First, you must understand that when you write javascript code it runs on client side and your c# code runs on server side. So you can have both, client validation written in javascript by attaching code to the onclick event and server validation written in C#. There's no ambiguity if that's what worries you. Hope this helps.

            Kenia

            C Offline
            C Offline
            compninja25
            wrote on last edited by
            #5

            Hi Kenia, Thanks for taking the time to respond :) I've done a lot of server side coding but there are some things that I would like to have the browser do without issuing a post back (server side). I was searching on google for a couple of hours before posting my question and I think by that point I was just so confused myself that I didn't word it too well. Turns out I was really just trying to figure out if it was possible to have the javascript do a post back so the server can perform what it needs to do. This way, I can have my submit button run the function on the client, and if there's a problem it can pop up a window right away before ever having to send any info back to the server :)

            Knowledge is not power, however, the acquisition and appropriate application of knowledge can make you a very powerful individual.

            1 Reply Last reply
            0
            • A Andrew Rissing

              What you're talking about doing is having the Javascript force a server side post back event. You might want to start looking at websites such as this[^].

              C Offline
              C Offline
              compninja25
              wrote on last edited by
              #6

              I also found this site very helpful in understanding the _doPostBack javascript function. aspalliance

              Knowledge is not power, however, the acquisition and appropriate application of knowledge can make you a very powerful individual.

              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