Link to home
Start Free TrialLog in
Avatar of Labelsoft
LabelsoftFlag for Netherlands

asked on

Button Click after Page Load?

Dear experts,

It's kind of a general question because I'm an ASP.NET noob (I come from Winforms).

I've got a page with a datagrid and a button. And this datagrid is databound to a collection. When the button is clicked I add an object to the collection in the click event. But the click event is handled after the load event of the page. So the added object is not immediatly visible in my databound datagrid.

To solve this I ask in the page load if the button was the control that caused the post back. If so, I add the object to the collection and rebind the collection to the datagrid.

It seems to me that this is not the way to go. Because I'll have to ask for every button on the page if it caused the post back if I want stuff to display immediatly on the page.

So help an ASP.NET noob out guys. How are webdevelopers supposed to implement the aformentioned setup?
ASKER CERTIFIED SOLUTION
Avatar of Cluskitt
Cluskitt
Flag of Portugal image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Labelsoft

ASKER

Thanks for the replies guys.

I understand now that changing the underlying collection does not trigger the datagrid to reload itself, but setting it's DataSource property again does.

This is strange to me see, because collections like BindingList in Winforms broadcast the event CollectionChanged which will cause databound controls to repaint themselves.

Anways, I applied all the suggestions you made and now it works. Awesome.