|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
|
Announcements
Chapters
Services
Feature Zones
|
Last update: 2008-10-10 Updated template solution To run the application, download and unzip it to a folder on your computer and open it with Visual Studio 2005 (Pro or Web Edition) and run it over the development server.
IntroductionI ran into the problem that my page was loaded twice after selecting a row in a If something is completely strange, then I always check it in FireFox and to no much surprise, there is only one request (the expected To sum it up:
Note: This behaviour is only present when using How I Would Do It When Everything Would Be CorrectThe following ASPX definition shows a <asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False"
DataSourceID="ObjectDataSource1"
OnSelectedIndexChanged="SelectedIndexChanged">
<Columns>
<asp:CommandField ButtonType="Image"
SelectImageUrl="~/Select.gif" ShowSelectButton="True" />
<asp:BoundField DataField="A" HeaderText="A" SortExpression="A" />
<asp:BoundField DataField="B" HeaderText="B" SortExpression="B" />
<asp:BoundField DataField="C" HeaderText="C" SortExpression="C" />
</Columns>
</asp:GridView>
This I spent some time Googling and found some workarounds. I assembled all the information that I found and show you in the following sections three workarounds along with their advantages and disadvantages. Solution 1 - Use CommandButton of Type Link and Add the Image as HTML in the Link TextThis is the simplest workaround. I simply change the type of the <asp:GridView ID="GridView2" runat="server" AutoGenerateColumns="False"
DataSourceID="ObjectDataSource1">
<Columns>
<asp:CommandField ShowSelectButton="True"
SelectText="<img src='Select.gif' border=0 title='This is a Tooltip'>">
</asp:CommandField>
<asp:BoundField DataField="A" HeaderText="A" SortExpression="A" />
<asp:BoundField DataField="B" HeaderText="B" SortExpression="B" />
<asp:BoundField DataField="C" HeaderText="C" SortExpression="C" />
</Columns>
</asp:GridView>
This works great but has one disadvantage: the localization of the tooltip text gets difficult. The whole HTML string has to be added to the local resource, which isn't quite nice. Solution 2 - Switch to TemplateFieldsTo get a solution that is better localizable, I delete the <asp:GridView ID="GridView3" runat="server" AutoGenerateColumns="False"
DataSourceID="ObjectDataSource1">
<Columns>
<asp:TemplateField ShowHeader="false">
<ItemStyle HorizontalAlign="Center" />
<ItemTemplate>
<asp:ImageButton ID="btnView" runat="server"
CausesValidation="False" CommandName="Select"
ImageUrl="~/Select.gif" ToolTip="View" />
</ItemTemplate>
</asp:TemplateField>
<asp:BoundField DataField="A" HeaderText="A" SortExpression="A" />
<asp:BoundField DataField="B" HeaderText="B" SortExpression="B" />
<asp:BoundField DataField="C" HeaderText="C" SortExpression="C" />
</Columns>
</asp:GridView>
Custom Commands SampleIn order to get your custom commands to work, you can either use a The following sample shows this together with the approaches that do not work (see Tooltip for explanation as to what happens): <asp:GridView ID="GridView4" runat="server" AutoGenerateColumns="False"
DataSourceID="ObjectDataSource1" OnRowCommand="RowCommand">
<Columns>
<asp:ButtonField ButtonType="Image" CommandName="MyCommand1"
ImageUrl="~/Select.gif"
Text="Double PostBack in IE7 (sometimes in IE6)" />
<asp:TemplateField ShowHeader="False">
<ItemStyle HorizontalAlign="Center" />
<ItemTemplate>
<asp:ImageButton ID="btnView" runat="server" CausesValidation="False"
CommandName="MyCommand2"
CommandArgument="<%# Container.DataItemIndex %>"
ImageUrl="~/Select.gif"
ToolTip="Works! Preferred solution." />
</ItemTemplate>
</asp:TemplateField>
<asp:ButtonField ButtonType="Link" CommandName="MyCommand3"
Text="<img src='Select.gif' border=0 title='Works! But bad localizable.'>"
/>
<asp:BoundField DataField="A" HeaderText="A" SortExpression="A" />
<asp:BoundField DataField="B" HeaderText="B" SortExpression="B" />
<asp:BoundField DataField="C" HeaderText="C" SortExpression="C" />
</Columns>
</asp:GridView>
ConclusionThere exists a problem in Internet Explorer that leads to multiple If you have further information or other/better workarounds or even real solutions, then PLEASE post them below!! History
|
||||||||||||||||||||||