Error on linkbutton click

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
Peter NordbergIT ManagerAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

safiintCommented:
add the link button and insure that its handler method take these parameters:

Sub NewButton_Click(ByVal sender As Object, ByVal e As EventArgs)
0
Richard LeeSoftware EnthusiastCommented:
Sounds like the method that is handling the click event has an incorrect signature for LinkButton. The LinkButton requires a signature of:

Sub LinkButton_Click(sender As Object, e As EventArgs)

while the ImageButton requires a signature of:

Sub LinkButton_Click(sender As Object, e As ImageClickEventArgs)

DaTribe
0
muhammadyasirCommented:
delete the onclick event of imagebutton and go to its desine view.then double click on image button.you will get the new onlclick event there put your functionality.
0
Cloud Class® Course: CompTIA Cloud+

The CompTIA Cloud+ Basic training course will teach you about cloud concepts and models, data storage, networking, and network infrastructure.

muhammadyasirCommented:
do this:
<asp:ImageButton ID="btnBuy" runat="server" CssClass="btnBuy" OnClick="" CommandArgument='<%#Eval("productID") %>' />

and then double click on the imagebutton in design view of page.
0
Peter NordbergIT ManagerAuthor Commented:
Hi and thanks for all your suggestions.
I've tried all three but get the same error message anyway. As I said, if I'm using an image button it works allright but not with the linkbutton.
Peter
0
Peter NordbergIT ManagerAuthor Commented:
This is what it looks like now

<asp:LinkButton ID="btnBuy" runat="server" Width="58px" CssClass="btnBuy" OnClick="btnBuy_Click" CommandArgument='<%# Eval("productID") %>'>Kp</asp:LinkButton>

Protected Sub btnBuy_Click(ByVal sender As Object, ByVal e As System.Web.UI.ImageClickEventArgs) Handles btnBuy.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
0
Richard LeeSoftware EnthusiastCommented:
Change to:

<asp:LinkButton ID="btnBuy" runat="server" Width="58px" CssClass="btnBuy" OnClick="btnBuy_Click" CommandArgument='<%# Eval("productID") %>'>Kp</asp:LinkButton>


Protected Sub btnBuy_Click(ByVal sender As Object, ByVal e As System.Web.UI.EventArgs) Handles btnBuy.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
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Richard LeeSoftware EnthusiastCommented:
Notice I changed the ImageClickEventArgs to EventArgs

DaTribe
0
muhammadyasirCommented:
TRY THIS
Protected Sub btnBuy_Click(ByVal sender As Object,  ByVal e As System.EventArgs) Handles btnBuy.Click
0
Peter NordbergIT ManagerAuthor Commented:
HI,

That worked. Thanks for your help!
Peter
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
.NET Programming

From novice to tech pro — start learning today.