[Webinar] Streamline your web hosting managementRegister Today

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 937
  • Last Modified:

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
0
peternordberg
Asked:
peternordberg
  • 3
  • 3
  • 3
  • +1
2 Solutions
 
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
Never miss a deadline with monday.com

The revolutionary project management tool is here!   Plan visually with a single glance and make sure your projects get done.

 
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
 
peternordbergAuthor 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
 
peternordbergAuthor 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
 
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
 
peternordbergAuthor Commented:
HI,

That worked. Thanks for your help!
Peter
0

Featured Post

Hire Technology Freelancers with Gigs

Work with freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely, and get projects done right.

  • 3
  • 3
  • 3
  • +1
Tackle projects and never again get stuck behind a technical roadblock.
Join Now