Peter Nordberg
asked on
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.ImageClickE ventArgs'.
-------------------------- --------
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_Web shop_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:RadAjaxManagerPro xy ID="RadAjaxManagerProxy1" runat="server">
<AjaxSettings>
<telerik:AjaxSetting AjaxControlID="btnBuy">
<UpdatedControls>
<telerik:AjaxUpdatedContro l ControlID="lblShopCartPric e" />
<telerik:AjaxUpdatedContro l ControlID="PanelCheckout" />
</UpdatedControls>
</telerik:AjaxSetting>
</AjaxSettings>
</telerik:RadAjaxManagerPr oxy>
-------------------------- ---------- ---------- ---------- ---
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(60 0)
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
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.ImageClickE
--------------------------
If I use an imagebutton instead it all works fine.
This is my usercontrol code:
--------------------------
<%@ Control Language="VB" AutoEventWireup="false" CodeFile="buyLink.ascx.vb"
<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("
<telerik:RadAjaxManagerPro
<AjaxSettings>
<telerik:AjaxSetting AjaxControlID="btnBuy">
<UpdatedControls>
<telerik:AjaxUpdatedContro
<telerik:AjaxUpdatedContro
</UpdatedControls>
</telerik:AjaxSetting>
</AjaxSettings>
</telerik:RadAjaxManagerPr
--------------------------
and this is my code behind:
--------------------------
Sub NewButton_Click()
If Request.Cookies("orderID")
Dim i As New orderDBL
i.InsertOrder()
Response.Cookies("orderID"
Response.Cookies("orderID"
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
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
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
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.
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.
<asp:ImageButton ID="btnBuy" runat="server" CssClass="btnBuy" OnClick="" CommandArgument='<%#Eval("
and then double click on the imagebutton in design view of page.
ASKER
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
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
ASKER
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.ImageClickEv entArgs) 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(60 0)
InsertProduct()
Else
InsertProduct()
End If
End Sub
<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.ImageClickEv
If Request.Cookies("orderID")
Dim i As New orderDBL
i.InsertOrder()
Response.Cookies("orderID"
Response.Cookies("orderID"
InsertProduct()
Else
InsertProduct()
End If
End Sub
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Notice I changed the ImageClickEventArgs to EventArgs
DaTribe
DaTribe
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
HI,
That worked. Thanks for your help!
Peter
That worked. Thanks for your help!
Peter
Sub NewButton_Click(ByVal sender As Object, ByVal e As EventArgs)