Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Repeater Command Not being executed

Posted on 2004-10-27
7
Medium Priority
?
1,107 Views
Last Modified: 2008-03-06
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
0
Comment
Question by:Charles Baldo
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
7 Comments
 
LVL 15

Assisted Solution

by:Thogek
Thogek earned 400 total points
ID: 12430437
Question:
Is the button's OnCommand="GalleryClicked" attribute serving any purpose?  (I.e., is there a GalleryClicked method?  If so, does it get called?)  If so, is there a reason to have both Repeater.OnItemCommand and Button.OnCommand specified (since the two would seem to conflict).

More about...
Repeater.OnItemCommand method: http://msdn.microsoft.com/library/en-us/cpref/html/frlrfsystemwebuiwebcontrolsrepeaterclassonitemcommandtopic.asp
Repeater.ItemCommand event: http://msdn.microsoft.com/library/en-us/cpref/html/frlrfsystemwebuiwebcontrolsrepeaterclassitemcommandtopic.asp
0
 
LVL 8

Accepted Solution

by:
daffodils earned 800 total points
ID: 12430453
I think your GalleryRepeater_ItemCommand() event handler is not wired to your Repeater control.

A simple example.. lets say you have a button control.
To wire your event handler to the Button, you must create an instance of EventHandler that takes a reference to Button_Clicked in its argument and add this delegate instance to the Click event.
So, you need something like this in your code:
AddHandler button.Click, AddressOf Me.Button_Clicked

You need to add a wiring for your Repeater control to its ItemCommand() event handler.

If you are using Visual Studio .NET, then all you have to do is double click the control in the design mode, and it will autogenerate this code for you.

>> I got this same code to work in an inline version  of the code
The reason this works in inline version is because the AutoEventWireup is true by default.. so an event handler like "control_event" gets automatically wired to a "control" 's  "event".

However in Visual Studio.. AutoEventWireup is false by default.. since it generates code for event handler wiring.
Now.. since you have copied and pasted code.. you can add 'event wiring':
 --- manually as in the above 'buttton" example
 --- or you can do it by double-clicking the control in design mode.
0
 
LVL 3

Assisted Solution

by:sajay
sajay earned 400 total points
ID: 12430458
attach the event to the button instead..

OnClick="ButtonClicked"
0
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 
LVL 28

Assisted Solution

by:mmarinov
mmarinov earned 400 total points
ID: 12430577
Hi charlesbaldo,

1. Have you bind the repeater in
If Not IsPostBack Then
End If
If you not - the behaviour will be as you write

2. Set a breakpoint in the GalleryRepeater_ItemCommand and GallerClicked, debug the application and see if there will be a problem
Regards!
B..M
0
 
LVL 28

Expert Comment

by:mmarinov
ID: 12430586
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
0
 

Author Comment

by:Charles Baldo
ID: 12430698
Where should I add the code

AddHandler button.Click, AddressOf Me.Button_Clicked

in the Page_Load??

Thank You
chuck
0
 
LVL 28

Expert Comment

by:mmarinov
ID: 12430739
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
0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article discusses the ASP.NET AJAX ModalPopupExtender control. In this article we will show how to use the ModalPopupExtender control, how to display/show/call the ASP.NET AJAX ModalPopupExtender control from javascript, how to show/display/cal…
In .NET 2.0, Microsoft introduced the Web Site.  This was the default way to create a web Project in Visual Studio 2005.  In Visual Studio 2008, the Web Application has been restored as the default web Project in Visual Studio/.NET 3.x The Web Si…
This course is ideal for IT System Administrators working with VMware vSphere and its associated products in their company infrastructure. This course teaches you how to install and maintain this virtualization technology to store data, prevent vuln…
This tutorial will teach you the special effect of super speed similar to the fictional character Wally West aka "The Flash" After Shake : http://www.videocopilot.net/presets/after_shake/ All lightning effects with instructions : http://www.mediaf…

609 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question