Link to home
Start Free TrialLog in
Avatar of Charles Baldo
Charles BaldoFlag for United States of America

asked on

Repeater Command Not being executed

Hello,
 I have a repeater with a button

<asp:Repeater id=GalleryRepeater  OnItemCommand="GalleryRepeater_ItemCommand" runat="server">
<ItemTemplate>
<asp:Button id="btnGallery" OnCommand="GalleryClicked" Text='<%# DataBinder.Eval(Container.DataItem, "Gallery")%>' CommandName="Display" CommandArgument='<%# DataBinder.Eval(Container.DataItem, "Gallery")%>' runat="server"></asp:Button>
</ItemTemplate>
</asp:Repeater>

The Button seems to be woring ok. The Text, CommandName, and CommandArgument are binded nicely with data

The problem is the buttons evenet never seems to fire

CodeBehind

Protected WithEvents GalleryRepeater As System.Web.UI.WebControls.Repeater
Protected WithEvents btnGallery As System.Web.UI.WebControls.Button

Public Sub GalleryRepeater_ItemCommand(ByVal sender As Object, ByVal e As RepeaterCommandEventArgs) Handles   GalleryRepeater.ItemCommand

      Response.Redirect("http://www.globalwindows.com")
      Response.Write(e.CommandArgument)

      Response.Write(e.CommandName)
      Response.Write(e.CommandSource)

End Sub

When the button is clicked the subroutine never seems to be called.  I got this same code to work in an inline version  of the code. I did a lot of cutting and pasting but think I got it right.

Any help is apprecited

Best
Chuck
SOLUTION
Avatar of Thogek
Thogek
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
ASKER CERTIFIED SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of mmarinov
mmarinov

daffodils,

when you put in the tag ( like in the code OnItemCommand="GalleryRepeater_ItemCommand" ) the event name and the method that will handle with it you don't have to add

AddHandler GalleryRepeater.ItemCommand, AddressOf Me.GalleryRepeater_ItemCommand

B..M
Avatar of Charles Baldo

ASKER

Where should I add the code

AddHandler button.Click, AddressOf Me.Button_Clicked

in the Page_Load??

Thank You
chuck
if you want to add this handler you have to create itemdatabound event and there

If e.Item.ItemType = ListItemType.Item Or e.Item.ItemType = ListItemType.Alternating Then
 Dim btn as Button = CType(e.Item.FIndControl("btnGallery"), Button )
 AddHandler btn.Click, AddressOf Me.Button_Clicked
End If

but you can not access direct the btnGallery because it is nested control

B..M