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 to run a method from codebehind when clicking on a

How to run a method from codebehind when clicking on a

Scheduled Pinned Locked Moved ASP.NET
questioncsharpjavaasp-nettutorial
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.
  • A Offline
    A Offline
    adfgh75
    wrote on last edited by
    #1

    I am quite new to ASP.NET and hope that there is an easy answer to my question.. My question is how can I access an function from codeBehind when I click on a

    in my application? I have a

    tag and when I click on the tag I want to run a function from codebehind to do some calulationes and then redirect the user to a new web page. However the onclick event för the

    tag is only for client side java scripts. Does anyone have a good answer? A.V

    E N A 3 Replies Last reply
    0
    • A adfgh75

      I am quite new to ASP.NET and hope that there is an easy answer to my question.. My question is how can I access an function from codeBehind when I click on a

      in my application? I have a

      tag and when I click on the tag I want to run a function from codebehind to do some calulationes and then redirect the user to a new web page. However the onclick event för the

      tag is only for client side java scripts. Does anyone have a good answer? A.V

      E Offline
      E Offline
      Edbert P
      wrote on last edited by
      #2

      You can try calling a Javascript when the div is clicked. The Javascript should submit your form and you might want to add additional query string to let the page knows your div is clicked. From there it's all the same as a postback from a button. "Democracy is two wolves and a sheep voting on what to have for dinner" - Ross Edbert Sydney, Australia

      1 Reply Last reply
      0
      • A adfgh75

        I am quite new to ASP.NET and hope that there is an easy answer to my question.. My question is how can I access an function from codeBehind when I click on a

        in my application? I have a

        tag and when I click on the tag I want to run a function from codebehind to do some calulationes and then redirect the user to a new web page. However the onclick event för the

        tag is only for client side java scripts. Does anyone have a good answer? A.V

        N Offline
        N Offline
        nrutter
        wrote on last edited by
        #3

        Try this. In the Page_Load method in the codebehind put: divButton.Attributes.Add("onclick",Page.GetPostBackEventReference(divButton)); NB. This needs to be executed everytime, so don't put it inside any if blocks. Now your page will post back when you click on the DIV. Next thing to do is to work out which control caused the postback so you can call a specific handler for your control. Check here for how to do this HTH

        1 Reply Last reply
        0
        • A adfgh75

          I am quite new to ASP.NET and hope that there is an easy answer to my question.. My question is how can I access an function from codeBehind when I click on a

          in my application? I have a

          tag and when I click on the tag I want to run a function from codebehind to do some calulationes and then redirect the user to a new web page. However the onclick event för the

          tag is only for client side java scripts. Does anyone have a good answer? A.V

          A Offline
          A Offline
          adfgh75
          wrote on last edited by
          #4

          For the help.. A.V

          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