Control causing postback?
-
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
-
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
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.
-
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.
no, didnt know, where do i do that? just need to call the same method from all of the dynamicly created buttons.
Regards, Tintin
-
no, didnt know, where do i do that? just need to call the same method from all of the dynamicly created buttons.
Regards, Tintin
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.
-
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
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