J
J055
Hi
I have a very simple configuration of the GridView with paging and sorting.
When I do a postback the DataBinding event fires twice - in both the
ProcessPostData and PreRender stages of the page life cycle.
In this example the event fires twice when a) GridView EnableViewState=False
and any image type control in the <columns/> element. When either
EnableViewState is set to true or the image button is removed, the event
fires once. Please see the code below:
Webpage
----------
....
<form id="UserAccounts" runat="server">
<div>
<asp:GridView ID="UserGrid" runat="server" AllowPaging="True"
AllowSorting="True"
AutoGenerateColumns="False" DataSourceID="SqlDataSource1"
OnDataBinding="UserGrid_DataBinding"
DataKeyNames="UserID" EnableViewState="False">
<Columns>
<asp:ButtonField ButtonType="Image" ImageUrl="~/images/Profile.gif"
Text="Permissions" />
<asp:BoundField DataField="UserID" HeaderText="UserID"
SortExpression="UserID" />
</Columns>
</asp:GridView>
<asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$
ConnectionStrings:AccountsModule%>"
ProviderName="System.Data.SqlClient"
SelectCommand="usp_Accounts_GetAllUsers"
SelectCommandType="StoredProcedure"></asp:SqlDataSource>
</div>
</form>
....
CodeBehind (this is the only code in the page class)
----------------------------------------------------
....
protected void UserGrid_DataBinding(object sender, EventArgs e)
{
Trace.Warn("UserGrid_DataBinding");
}
....
Is there a way to stop this happening without having to EnableViewState?
This would add completely unnecessary overhead to the page.
Any suggestions/comments/workarounds will be very welcome.
Many thanks
Andrew
More background to this here:
http://groups.google.co.uk/group/mi...read/thread/48e3d4d143cd685f/487449f35f61bbf3
I have a very simple configuration of the GridView with paging and sorting.
When I do a postback the DataBinding event fires twice - in both the
ProcessPostData and PreRender stages of the page life cycle.
In this example the event fires twice when a) GridView EnableViewState=False
and any image type control in the <columns/> element. When either
EnableViewState is set to true or the image button is removed, the event
fires once. Please see the code below:
Webpage
----------
....
<form id="UserAccounts" runat="server">
<div>
<asp:GridView ID="UserGrid" runat="server" AllowPaging="True"
AllowSorting="True"
AutoGenerateColumns="False" DataSourceID="SqlDataSource1"
OnDataBinding="UserGrid_DataBinding"
DataKeyNames="UserID" EnableViewState="False">
<Columns>
<asp:ButtonField ButtonType="Image" ImageUrl="~/images/Profile.gif"
Text="Permissions" />
<asp:BoundField DataField="UserID" HeaderText="UserID"
SortExpression="UserID" />
</Columns>
</asp:GridView>
<asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$
ConnectionStrings:AccountsModule%>"
ProviderName="System.Data.SqlClient"
SelectCommand="usp_Accounts_GetAllUsers"
SelectCommandType="StoredProcedure"></asp:SqlDataSource>
</div>
</form>
....
CodeBehind (this is the only code in the page class)
----------------------------------------------------
....
protected void UserGrid_DataBinding(object sender, EventArgs e)
{
Trace.Warn("UserGrid_DataBinding");
}
....
Is there a way to stop this happening without having to EnableViewState?
This would add completely unnecessary overhead to the page.
Any suggestions/comments/workarounds will be very welcome.
Many thanks
Andrew
More background to this here:
http://groups.google.co.uk/group/mi...read/thread/48e3d4d143cd685f/487449f35f61bbf3