1

i am using image button and link button in list view and binding data in onload method.oncommand for image button is working fine but oncommand for link button is not firing here is code of list view:

<asp:Content ID="Content1" ContentPlaceHolderID="ContentPlaceHolder1" Runat="Server">
 <asp:ListView runat="server" ID="List1" >
            <ItemTemplate>
                <table>
                    <tr>
                        <td>
                            <asp:ImageButton runat="server" ID="imagebutton" ImageUrl='<%# Eval("image") %>' CommandArgument='<%# Eval("id") %>' CommandName="button"  Width="100px" Height="100px" OnCommand="imagebutton_Command" ></asp:ImageButton>
                        </td>
                        <td>
                            <asp:LinkButton ID="title" runat="server" Text='<%# Eval("title") %>' CommandArgument='<%# Eval("id") %>' CommandName="link" OnCommand="imagebutton_Command"></asp:LinkButton></td>

                    </tr>
                </table>
            </ItemTemplate>
        </asp:ListView>
</asp:Content>

and code for oncommad event is:

 protected void imagebutton_Command(object sender, CommandEventArgs e)
 {
    try
    {


        Response.Redirect("Welcome.aspx?url=" + e.CommandArgument.ToString());
    }
    catch (Exception ex)
    {
        ex.ToString();
    }
}

I also tried break point on oncommand method but when i click on image button it works fine but when i click on link button it does not fired and does not come in oncommad block

Ali Khan
  • 11
  • 1
  • 1
    Do you databind the `ListView` only `if(!IsPostBack)`? Show your `Page_Load`. – Tim Schmelter Mar 25 '15 at 13:35
  • yes i did protected void Page_Load(object sender, EventArgs e) { if (!IsPostBack) { List1.DataSource = Driver.alldata(); List1.DataBind(); } } – Ali Khan Mar 25 '15 at 15:26
  • one thing more if i use this listview without Master page.. then oncommand of link button works fine – Ali Khan Mar 25 '15 at 15:40

0 Answers0