We help IT Professionals succeed at work.
Get Started

Error on linkbutton click

1,001 Views
Last Modified: 2013-11-26
Hi,

I have this usercontrol where I have a linkbutton that I want to handle some code behind when I click on it. The usercontrol is a part of a datalist control. Unfortunately I get an error when I click it:
-----------------------------------
Unable to cast object of type 'System.EventArgs' to type 'System.Web.UI.ImageClickEventArgs'.
----------------------------------
If I use an imagebutton instead it all works fine.

This is my usercontrol code:
------------------------------------------------
<%@ Control Language="VB" AutoEventWireup="false" CodeFile="buyLink.ascx.vb" Inherits="UserControls_Webshop_buy" %>

<asp:HiddenField ID="productID" runat="server" />
<asp:LinkButton ID="btnBuy" runat="server" Width="58px" CssClass="btnBuy" OnClick="NewButton_Click" CommandArgument='<%# Eval("productID") %>'>Köp</asp:LinkButton>
<%--<asp:ImageButton ID="btnBuy" runat="server" CssClass="btnBuy" OnClick="NewButton_Click" CommandArgument='<%#Eval("productID") %>' />--%>
<telerik:RadAjaxManagerProxy ID="RadAjaxManagerProxy1" runat="server">
    <AjaxSettings>
        <telerik:AjaxSetting AjaxControlID="btnBuy">
            <UpdatedControls>
                <telerik:AjaxUpdatedControl ControlID="lblShopCartPrice" />
                <telerik:AjaxUpdatedControl ControlID="PanelCheckout" />
            </UpdatedControls>
        </telerik:AjaxSetting>
    </AjaxSettings>
</telerik:RadAjaxManagerProxy>
-----------------------------------------------------------
and this is my code behind:
---------------------------------
Sub NewButton_Click()
        If Request.Cookies("orderID") Is Nothing Then
            Dim i As New orderDBL
            i.InsertOrder()

            Response.Cookies("orderID").Value = i.orderID
            Response.Cookies("orderID").Expires = DateTime.Now.AddSeconds(600)


            InsertProduct()

        Else

            InsertProduct()

        End If
    End Sub
-------------------------------------------

I would like to use the linkbutton instead of the imagebutton but I'm not sure how I can fix this error.

Peter
Comment
Watch Question
Serves the Most High - Not Religion
CERTIFIED EXPERT
Commented:
This problem has been solved!
Unlock 2 Answers and 10 Comments.
See Answers
Why Experts Exchange?

Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.

Jim Murphy
Programmer at Smart IT Solutions

When asked, what has been your best career decision?

Deciding to stick with EE.

Mohamed Asif
Technical Department Head

Being involved with EE helped me to grow personally and professionally.

Carl Webster
CTP, Sr Infrastructure Consultant
Ask ANY Question

Connect with Certified Experts to gain insight and support on specific technology challenges including:

  • Troubleshooting
  • Research
  • Professional Opinions
Did You Know?

We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE