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. DIV onclick postback - how to identify on the server side?

DIV onclick postback - how to identify on the server side?

Scheduled Pinned Locked Moved ASP.NET
questionsysadminhelptutorial
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
    Chris Buckett
    wrote on last edited by
    #1

    Can anyone help with this? I have an aspx page with 2 divs both marked to run at server.

    <div id="div1" runat="server">
    this is div 1
    </div>

    <div id="div2" runat="server">
    this is div 2
    </div>

    In the page load, I dynamically add a clientside onclick postback to the divs like so:

    if (!IsPostBack)
    {
    div1.Attributes.Add("onclick",
    Page.ClientScript.GetPostBackClientHyperlink(div1, ""));
    div2.Attributes.Add("onclick",
    Page.ClientScript.GetPostBackClientHyperlink(div2, ""));
    }

    When I click on the div it postbacks ok, but the question is, how do I identify on the server which div sent the postback? (or have I got the wrong end of the stick)? Cheers

    ChrisB

    E M 2 Replies Last reply
    0
    • C Chris Buckett

      Can anyone help with this? I have an aspx page with 2 divs both marked to run at server.

      <div id="div1" runat="server">
      this is div 1
      </div>

      <div id="div2" runat="server">
      this is div 2
      </div>

      In the page load, I dynamically add a clientside onclick postback to the divs like so:

      if (!IsPostBack)
      {
      div1.Attributes.Add("onclick",
      Page.ClientScript.GetPostBackClientHyperlink(div1, ""));
      div2.Attributes.Add("onclick",
      Page.ClientScript.GetPostBackClientHyperlink(div2, ""));
      }

      When I click on the div it postbacks ok, but the question is, how do I identify on the server which div sent the postback? (or have I got the wrong end of the stick)? Cheers

      ChrisB

      E Offline
      E Offline
      enjoycrack
      wrote on last edited by
      #2

      Hi Chris: Here is just a suggestion...Before do postback, you store div id into a hidden field...then you can parse this at server side to know which div causes post back... Hope you get the clue... << >>

      1 Reply Last reply
      0
      • C Chris Buckett

        Can anyone help with this? I have an aspx page with 2 divs both marked to run at server.

        <div id="div1" runat="server">
        this is div 1
        </div>

        <div id="div2" runat="server">
        this is div 2
        </div>

        In the page load, I dynamically add a clientside onclick postback to the divs like so:

        if (!IsPostBack)
        {
        div1.Attributes.Add("onclick",
        Page.ClientScript.GetPostBackClientHyperlink(div1, ""));
        div2.Attributes.Add("onclick",
        Page.ClientScript.GetPostBackClientHyperlink(div2, ""));
        }

        When I click on the div it postbacks ok, but the question is, how do I identify on the server which div sent the postback? (or have I got the wrong end of the stick)? Cheers

        ChrisB

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

        At the server side, you simply check on the Request.Form["__EVENTTARGET"] entry to see which object causes the postback, for example if you click the div 1 then the value should be "div1". In addition, you might think about building a custom div control with a custom event, say Click, and you can easily determine which div causing the postback using the sender object of the Click event handler.

        C 1 Reply Last reply
        0
        • M minhpc_bk

          At the server side, you simply check on the Request.Form["__EVENTTARGET"] entry to see which object causes the postback, for example if you click the div 1 then the value should be "div1". In addition, you might think about building a custom div control with a custom event, say Click, and you can easily determine which div causing the postback using the sender object of the Click event handler.

          C Offline
          C Offline
          Chris Buckett
          wrote on last edited by
          #4

          Perfect, Thanks.

          ChrisB

          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