Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Wanet Telecoms Ltd on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to post back text box with image as button 1

Status
Not open for further replies.

bernie321

Programmer
Jan 7, 2004
477
GB
Hi

We have a repeater that lists our stock, users can then enter the quantity in a text box and click an image which is the add to cart button.

I have two problems:

1 - how do I use an image to post the item
2 - how do I know the name of the correct quantity textbox (as there are many created for each record by the repeater)

Any advice would be much appreciated.

Thanks
B
 
Hi

Thanks for your post & sorry for the delay in getting back to you, i have my image button in the repeater but am unable to catch the event:

<asp:Repeater ID="objRepeater" runat="server" OnItemCommand="objRepeater_ItemCommand">
<ItemTemplate>
<asp:ImageButton id="imgDelete" CommandName="imgDelete_Click" runat="server" ImageUrl="delete.jpg"></asp:ImageButton>
</ItemTemplate>
</asp:Repeater>


Protected Sub objRepeater_ItemCommand(ByVal source As Object, ByVal e As System.Web.UI.WebControls.RepeaterCommandEventArgs) Handles objRepeater.ItemCommand

If e.CommandName = "imgDelete_Click" Then

clsBasketClass.gsubRemoveFromCart(e.Item.ItemIndex)
End If

End Sub


Any help would be much appreciated

Thanks
B
 
Have you stepped through the code and do you reach the line "clsBasketClass.gsubRemoveFromCart(e.Item.ItemIndex)" ? (I'm not asking if it exectues successfully right now)

:)
 
Hi

Thanks for your post, and again sorry for the delay.

We have a breakpoint on clsBasket.... but it does not reach this.

Thanks
B
 
Hi

Thanks for your post.

E is empty, there is no CommandName

Thanks
B
 
So you are saying that the event actually fires correctly (i.e. when you put a breakpoint on the event it gets hit), but that e.CommandName is empty?


-------------------------------------------------------

Mark,
[URL unfurl="true"]http://aspnetlibrary.com[/url]
[URL unfurl="true"]http://mdssolutions.co.uk[/url] - Delivering professional ASP.NET solutions
[URL unfurl="true"]http://weblogs.asp.net/marksmith[/url]
 
Sorry, no the breakpoint is in the page load for checking the e.commandname...

The event does not fire.
 
Sorry, Again just to confirm:

I have two breakpoints:

One in the page load (which did break) - (this is the point at which I checked the e.commandarguement but realise this was incorrect as it would have a different value to in the event?)

One in the event (which did not fire)
 
If the one in the event did not fire then it is not causing the command to be raised. Change the ImageButton to a regular Button and see if that causes the breakpoint to be hit (my guess is that it will).


-------------------------------------------------------

Mark,
[URL unfurl="true"]http://aspnetlibrary.com[/url]
[URL unfurl="true"]http://mdssolutions.co.uk[/url] - Delivering professional ASP.NET solutions
[URL unfurl="true"]http://weblogs.asp.net/marksmith[/url]
 
Hi

I have replaced the image button with a regular button and again it did not fire.

Thanks
B
 
It fires fine in my simple test:
Code:
<%@ Page Language="VB" AutoEventWireup="false" CodeFile="Default87.aspx.vb" Inherits="Default87" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "[URL unfurl="true"]http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">[/URL]

<html xmlns="[URL unfurl="true"]http://www.w3.org/1999/xhtml"[/URL] >
<head runat="server">
    <title>Untitled Page</title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
        <asp:Repeater ID="objRepeater" runat="server">
           <ItemTemplate>   
              <asp:Button id="imgDelete" CommandName="imgDelete_Click" runat="server"></asp:Button>
           </ItemTemplate>
        </asp:Repeater>        
    </div>
    </form>
</body>
</html>
Code:
Imports System.Data
Partial Class Default87
    Inherits System.Web.UI.Page

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        If Not Page.IsPostBack Then
            objRepeater.DataSource = BindData()
            objRepeater.DataBind()
        End If
    End Sub

    Private Function BindData()
        Dim dt As New DataTable
        Dim dr As DataRow
        dt.Columns.Add("one")

        For i As Integer = 0 To 10
            dr = dt.NewRow
            dr(0) = i
            dt.Rows.Add(dr)
        Next

        Return dt
    End Function

    Protected Sub objRepeater_ItemCommand(ByVal source As Object, ByVal e As System.Web.UI.WebControls.RepeaterCommandEventArgs) Handles objRepeater.ItemCommand
        Response.Write("I Fired")
    End Sub
End Class



-------------------------------------------------------

Mark,
[URL unfurl="true"]http://aspnetlibrary.com[/url]
[URL unfurl="true"]http://mdssolutions.co.uk[/url] - Delivering professional ASP.NET solutions
[URL unfurl="true"]http://weblogs.asp.net/marksmith[/url]
 
Thank you for your post.

You will not believe my stupidity!!!

"If Not Page.IsPostBack Then"

I had left the databind in the postback code.

Thank you all for your help!!

B
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top