James123
James123

Reputation: 11652

Gridview Image Button RowCommand not working in IE?

I have Image button in gridview item template. When click on that image in RowCommand event CommandName is showing different then what I am expecting. It always says "Select", But I am expecting "pdf".

This is only happening in IE. Not Chrome.

 <asp:GridView ID="grdLoan" Width="100%" runat="server" CssClass="grid" HeaderStyle-CssClass="gridHeader"
                PageSize="25" AutoGenerateColumns="false" RowStyle-CssClass="gridItem" AlternatingRowStyle-CssClass="gridAltItem"
                AllowPaging="false" BackColor="LightGray">
                <SelectedRowStyle CssClass="SelectedRowStyle" />
                <Columns>
                    <asp:BoundField HeaderText="Loan Number" DataField="strAltLoanNumber">
                        <ItemStyle Wrap="False" />
                    </asp:BoundField>
                    <asp:BoundField HeaderText="Security" DataField="strGlobalSecurity">
                        <ItemStyle Wrap="False" />
                    </asp:BoundField>
                    <asp:BoundField HeaderText="Sample #" DataField="intSampleID"></asp:BoundField>
                    <asp:TemplateField HeaderText="PDF">
                        <ItemTemplate>
                            <asp:ImageButton CommandName="pdf" ID="imgPDF" ImageUrl="~/Images/pdf.png" runat="server"
                                CommandArgument='<%#Eval("strGlobalLoanNumber")%>' />
                        </ItemTemplate>
                    </asp:TemplateField>
                </Columns>
  </asp:GridView>

Gridview Events

Private Sub grdLoan_RowCreated(sender As Object, e As GridViewRowEventArgs) Handles grdLoan.RowCreated

    If e.Row.RowType = DataControlRowType.DataRow Then
        e.Row.Attributes("onmouseover") = "this.style.cursor='pointer';"
        e.Row.Attributes("onmouseout") = "this.style.textDecoration='none';"
        e.Row.ToolTip = "Click to select row"
        e.Row.Attributes("onclick") = Me.Page.ClientScript.GetPostBackClientHyperlink(Me.grdLoan, "Select$" & e.Row.RowIndex)
    End If
End Sub  

  Private Sub grdLoan_RowCommand(sender As Object, e As GridViewCommandEventArgs) Handles grdLoan.RowCommand
        If e.CommandName = "pdf" Then
        end if
End sub

Even I tried

<asp:ImageButton CommandName="pdf" ID="imgPDF" ImageUrl="~/Images/pdf.png"
 runat="server" CommandArgument='<%#Eval("strNumber")%>' OnClick="imgPDF_Click" />

Onclick event never fires and Chrome its working.

Also tried

<asp:CommandField ShowEditButton ...>

First time RowCommand firing twice. once Edit and another one is select. If I click second time it is Select.

I don't understand whats going on.

Upvotes: 1

Views: 2958

Answers (3)

nZeus
nZeus

Reputation: 2504

Please check your Page_Load method and ensure that you bind your grid inside the IsPostback check:

protected void Page_Load(object sender, EventArgs e)
{
    if(!Page.IsPostBack) // Don't forget this
    {
        grdLoan.DataSource = ...;
        grdLoan.DataBind();
    }
}

Upvotes: 0

Sunil Devre
Sunil Devre

Reputation: 384

i check your code but it's working here i am using IE 8 and its working in it.

what i changed:

<asp:GridView ID="grdLoan" Width="100%" runat="server" CssClass="grid" HeaderStyle-   CssClass="gridHeader" PageSize="25" AutoGenerateColumns="false"
 RowStyle-CssClass="gridItem" **onRowCommand = "grdLoan_RowCommand"** AlternatingRowStyle- CssClass="gridAltItem" AllowPaging="false" BackColor="LightGray">

and in code page

protected void grdLoan_RowCommand(object sender, GridViewCommandEventArgs e)
    {
        if (e.CommandName.ToLower() == "pdf")
        {
        }
    }

i am getting commandname properly in IE 8...

Upvotes: 1

nZeus
nZeus

Reputation: 2504

Sorry, I didn't see that you have an ID.

I think you're using the IE 10.

There is a bug in the browser definition files that shipped with .NET 2.0 and .NET 4, namely that they contain definitions for a certain range of browser versions. But the versions for some browsers (like IE 10) aren't within those ranges any more. Therefore, ASP.NET sees them as unknown browsers and defaults to a down-level definition, which has certain inconveniences, like that it does not support features like JavaScript.

Simply installing .NET Framework 4.5 can fix this problem.

This can fix the problem even if you do not switch your application pool over to .NET Framework 4.5.

Related: ImageButton does not fire a post back on IE10

Upvotes: 0

Related Questions