I am trying to display a table dynamically loaded from database with dynamically created button in the first cell of each row. Each button has assigned ROW_ID value that uniquely identifies the button in one “generic” method handler.
As far as I can understand the only way I can do this is by loading data and displaying it & wiring-up buttons to handler during Init life-cycle phase. The problem I am facing is when this button would (for example purposes) were to call delete (or other modification) procedure in the database for that particular row I would have to do Response.End and reload the page to reflect this modification, because during PostBack handlers its already too late to re-fetch new dataset from DB and create new set of buttons and wire it to the handler. Full page reload however losses state for all controls, which is not desirable.
One thing to note: I am using custom-render user control to display the resultset from database (it looks like a table though). I am not using DataGridView with DataBinding.
Possible solution would be to use radio-button for each row and one static button in the bottom, but this is far from ideal.
The questions is: Whats better way to do this? Am I missing something? I find it hard to believe that ASP.NET would be this cumbersome to handle this generic use case.
Thanks for any possible suggestions.
The solution I have ended-up with is to use JavaScript based __doPostBack( ‘static_button_id’, ‘row_id’ ) on a dummy button for each row. It generates postback with argument that identifies the row for which this post-back occurred.
Button (ID=static_button_id) is derived classical button that is hidden on the page via style=”display:none;” and on click calls custom handler (assigned during init/load phase). Its derived to circumvent the postback validation of arguments.
To retrieve parameter (row_id) inside a .NET handler I use:
string passedArgument = Request.Params.Get(“__EVENTARGUMENT”);
It does exactly what I need, but its somewhat dirty. I would still appreciate if anyone offered the clean way to do this.
Thanks.