I'm a newbie to ASP.NET, so my question might be a little dumb. Let's say we have a web form with two buttons and a gridview, here is some code
protected void button1_Click(object sender, EventArgs e)
{
...retrieve data from database and bind Dataset to gridview.
}
protected void button2_Click(object sender, EventArgs e)
{
// do nothing
}
So when I click button1, it displays the gridview with data, fair enough, that's what it should be. But it still displays the gridview with data when I click button2 which does nothing, from my understanding, when I click button2, there is a new postback request to reload and send a new page back, since button2 does nothing, there shouldn't be anything binded with the gridview, so the page should display nothing? But it still displays the gridview with data...
here is a quick example demonstrating what VDWWD pointed out.
make a new webform. copy paste the code below. hit the first button the gridview loads, hit the second button you get a postback but the gridview remains.
now go into the aspx page and change EnableViewState="true" to EnableViewState="false" and run it again this time when you click the second button the gridview data is not persisted.
webform1.aspx
webform1.aspx.cs