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. Control causing postback?

Control causing postback?

Scheduled Pinned Locked Moved ASP.NET
question
5 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.
  • T Offline
    T Offline
    TintinV3ck
    wrote on last edited by
    #1

    Hi, Im generating button controls at runtime in a gridview, and need to handle an event on click. so i need to identify the control doing the postback.

    Regards, Tintin

    M R 2 Replies Last reply
    0
    • T TintinV3ck

      Hi, Im generating button controls at runtime in a gridview, and need to handle an event on click. so i need to identify the control doing the postback.

      Regards, Tintin

      M Offline
      M Offline
      Mircea Grelus
      wrote on last edited by
      #2

      First of all because you are dealig with dinamically created controls, you are aware that you need to recreate them on postback right? This[^] will give you a clue about finding out which control generated the postback.

      regards, Mircea Many people spend their life going to sleep when they’re not sleepy and waking up while they still are.

      T 1 Reply Last reply
      0
      • M Mircea Grelus

        First of all because you are dealig with dinamically created controls, you are aware that you need to recreate them on postback right? This[^] will give you a clue about finding out which control generated the postback.

        regards, Mircea Many people spend their life going to sleep when they’re not sleepy and waking up while they still are.

        T Offline
        T Offline
        TintinV3ck
        wrote on last edited by
        #3

        no, didnt know, where do i do that? just need to call the same method from all of the dynamicly created buttons.

        Regards, Tintin

        M 1 Reply Last reply
        0
        • T TintinV3ck

          no, didnt know, where do i do that? just need to call the same method from all of the dynamicly created buttons.

          Regards, Tintin

          M Offline
          M Offline
          Mircea Grelus
          wrote on last edited by
          #4

          The thing is that the postback resets the page to it's original state, so any information regarding the dynamically created controls is lost. Why is that? Because the Page class is stateless. The Page recreates child controls based on the tags in the aspx files, so your controls not being present there are not shown. What you need to do is recreate the controls in the OnInit event or any event that fires before PageLoad, or in PageLoad if you do a check to see is the page is posted back. See this article[^]as an example.

          regards, Mircea Many people spend their life going to sleep when they’re not sleepy and waking up while they still are.

          1 Reply Last reply
          0
          • T TintinV3ck

            Hi, Im generating button controls at runtime in a gridview, and need to handle an event on click. so i need to identify the control doing the postback.

            Regards, Tintin

            R Offline
            R Offline
            Ramasubramaniam
            wrote on last edited by
            #5

            Hi, You can declare an event delegate for the button click event, and each button instace command argument property you can add some key to identify the button, then on the click event you can easily identify the event gets fired from which button, if you need code feel free to tell me. Ram

            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