473,406 Members | 2,369 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,406 software developers and data experts.

HTMLAnchor inside a repeater

I have an HTMLAnchor control on my aspx page. When it's not inside a
repeater, it works fine. When I put it inside a repeater control, the handler
never gets fired. I have a handler for the htmlAnchor's ServerClick event
(works when not inside a repeater), and a handler for the repeater's
ItemCommand event. My html and vb source code is shown below, but what I
think I need is a simple working example in vb.net. Can anyone help?
======================================
<a ID="haAnchor" OnServerClick="haAnchor_Click" runat="server">Click here</a>
======================================
In my code behind:
======================================
....
Protected WithEvents haAnchor As System.Web.UI.HtmlControls.HtmlAnchor
....

Public Sub haAnchor_Click(ByVal sender As Object, ByVal e As EventArgs)
Handles haAnchor.ServerClick
Me.Label1.Text = "HTML Anchor ServerClick fired!"
End Sub
======================================

When I put my HTMLAnchor control inside a repeater, the ServerClick event
does not fire:
=========================================
<table>
<asp:Repeater id=rpCustomers OnItemCommand="rpCustomers_ItemCommand"
EnableViewState="False" runat="server" DataSource="<%# dvwCustomerDisplays
%>">
<ItemTemplate>
<tr>
<td>
<a ID="haAnchor" OnServerClick="haAnchor_Click" runat="server">Click
here</a>
</td>
</tr>
</ItemTemplate>
</asp:Repeater>
</table>
=====================================
In my code behind, I have the same handler as before, plus this one:
=====================================
Public Sub rpCustomers_ItemCommand(ByVal source As Object, ByVal e As
System.Web.UI.WebControls.RepeaterCommandEventArgs ) Handles
rpCustomers.ItemCommand
Me.Label1.Text = "HTML Anchor ItemCommand fired!"
End Sub
======================================
Nov 18 '05 #1
3 5652
Hi Leigh,

I'm not clear on what you're aiming to accomplish, but here's what I managed
to do with your code:
<table border="1">
<asp:repeater id="rpCustomers"
OnItemCommand="rpCustomers_ItemCommand" EnableViewState="False"
runat="server">
<itemtemplate>
<tr>
<td>
<a id="haAnchor"
onserverclick="haAnchor_Click" runat="server">Click here</a>
</td>
</tr>
</itemtemplate>
</asp:repeater>
</table>
</form>
<p>&nbsp;</p>
<p>
<asp:label id="Label1" runat="server">Label</asp:label></p>

Private Sub Page_Load(ByVal sender As System.Object, _
ByVal e As System.EventArgs) Handles MyBase.Load
Dim dvwCustomerDisplays As DataView
dvwCustomerDisplays = CreateDataSource().DefaultView
rpCustomers.DataSource = dvwCustomerDisplays
rpCustomers.DataBind()
End Sub

Public Sub haAnchor_Click(ByVal sender As Object, _
ByVal e As System.EventArgs)
Dim htmlAnchor As HtmlAnchor
htmlAnchor = sender
Label1.Text = "HTML Anchor ServerClick fired!" & _
htmlAnchor.UniqueID
End Sub

Public Sub rpCustomers_ItemCommand(ByVal source As Object, _
ByVal e As System.Web.UI.WebControls.RepeaterCommandEventArgs ) _
Handles rpCustomers.ItemCommand
Response.Write(e.Item.ItemIndex.ToString)
End Sub

Function CreateDataSource() As DataTable
Dim dt As New DataTable
Dim dr As DataRow
dt.Columns.Add(New DataColumn _
("IntegerValue", GetType(Int32)))
dt.Columns.Add(New DataColumn _
("StringValue", GetType(String)))
dt.Columns.Add(New DataColumn _
("CurrencyValue", GetType(Double)))
dt.Columns.Add(New DataColumn _
("Boolean", GetType(Boolean)))
Dim i As Integer
For i = 0 To 8
dr = dt.NewRow()
dr(0) = i
dr(1) = "Item " + i.ToString()
dr(2) = 1.23 * (i + 1)
dr(3) = (i = 4)
dt.Rows.Add(dr)
Next i
Return dt
End Function 'CreateDataSource
"Leigh Webber" <Le*********@discussions.microsoft.com> wrote in message
news:61**********************************@microsof t.com...
I have an HTMLAnchor control on my aspx page. When it's not inside a
repeater, it works fine. When I put it inside a repeater control, the
handler
never gets fired. I have a handler for the htmlAnchor's ServerClick event
(works when not inside a repeater), and a handler for the repeater's
ItemCommand event. My html and vb source code is shown below, but what I
think I need is a simple working example in vb.net. Can anyone help?
======================================
<a ID="haAnchor" OnServerClick="haAnchor_Click" runat="server">Click
here</a>
======================================
In my code behind:
======================================
...
Protected WithEvents haAnchor As System.Web.UI.HtmlControls.HtmlAnchor
...

Public Sub haAnchor_Click(ByVal sender As Object, ByVal e As EventArgs)
Handles haAnchor.ServerClick
Me.Label1.Text = "HTML Anchor ServerClick fired!"
End Sub
======================================

When I put my HTMLAnchor control inside a repeater, the ServerClick event
does not fire:
=========================================
<table>
<asp:Repeater id=rpCustomers OnItemCommand="rpCustomers_ItemCommand"
EnableViewState="False" runat="server" DataSource="<%# dvwCustomerDisplays
%>">
<ItemTemplate>
<tr>
<td>
<a ID="haAnchor" OnServerClick="haAnchor_Click"
runat="server">Click
here</a>
</td>
</tr>
</ItemTemplate>
</asp:Repeater>
</table>
=====================================
In my code behind, I have the same handler as before, plus this one:
=====================================
Public Sub rpCustomers_ItemCommand(ByVal source As Object, ByVal e As
System.Web.UI.WebControls.RepeaterCommandEventArgs ) Handles
rpCustomers.ItemCommand
Me.Label1.Text = "HTML Anchor ItemCommand fired!"
End Sub
======================================


Nov 18 '05 #2
Thanks, Ken. The problem was that I had omitted the quotation marks around
the repeater's ID attribute. IOW, I had:

<asp:repeater id=rpCustomers ...

when I should have had:

<asp:repeater id="rpCustomers" ...

Sheesh -- can I please have the four hours back I spent chasing my tail on
this one? What a bonehead. :-(

Hmmm -- too bad the syntax checker doesn't pick this one up.

"Ken Cox [Microsoft MVP]" wrote:
Hi Leigh,

I'm not clear on what you're aiming to accomplish, but here's what I managed
to do with your code:
<table border="1">
<asp:repeater id="rpCustomers"
OnItemCommand="rpCustomers_ItemCommand" EnableViewState="False"
runat="server">
<itemtemplate>
<tr>
<td>
<a id="haAnchor"
onserverclick="haAnchor_Click" runat="server">Click here</a>
</td>
</tr>
</itemtemplate>
</asp:repeater>
</table>
</form>
<p> </p>
<p>
<asp:label id="Label1" runat="server">Label</asp:label></p>

Private Sub Page_Load(ByVal sender As System.Object, _
ByVal e As System.EventArgs) Handles MyBase.Load
Dim dvwCustomerDisplays As DataView
dvwCustomerDisplays = CreateDataSource().DefaultView
rpCustomers.DataSource = dvwCustomerDisplays
rpCustomers.DataBind()
End Sub

Public Sub haAnchor_Click(ByVal sender As Object, _
ByVal e As System.EventArgs)
Dim htmlAnchor As HtmlAnchor
htmlAnchor = sender
Label1.Text = "HTML Anchor ServerClick fired!" & _
htmlAnchor.UniqueID
End Sub

Public Sub rpCustomers_ItemCommand(ByVal source As Object, _
ByVal e As System.Web.UI.WebControls.RepeaterCommandEventArgs ) _
Handles rpCustomers.ItemCommand
Response.Write(e.Item.ItemIndex.ToString)
End Sub

Function CreateDataSource() As DataTable
Dim dt As New DataTable
Dim dr As DataRow
dt.Columns.Add(New DataColumn _
("IntegerValue", GetType(Int32)))
dt.Columns.Add(New DataColumn _
("StringValue", GetType(String)))
dt.Columns.Add(New DataColumn _
("CurrencyValue", GetType(Double)))
dt.Columns.Add(New DataColumn _
("Boolean", GetType(Boolean)))
Dim i As Integer
For i = 0 To 8
dr = dt.NewRow()
dr(0) = i
dr(1) = "Item " + i.ToString()
dr(2) = 1.23 * (i + 1)
dr(3) = (i = 4)
dt.Rows.Add(dr)
Next i
Return dt
End Function 'CreateDataSource
"Leigh Webber" <Le*********@discussions.microsoft.com> wrote in message
news:61**********************************@microsof t.com...
I have an HTMLAnchor control on my aspx page. When it's not inside a
repeater, it works fine. When I put it inside a repeater control, the
handler
never gets fired. I have a handler for the htmlAnchor's ServerClick event
(works when not inside a repeater), and a handler for the repeater's
ItemCommand event. My html and vb source code is shown below, but what I
think I need is a simple working example in vb.net. Can anyone help?
======================================
<a ID="haAnchor" OnServerClick="haAnchor_Click" runat="server">Click
here</a>
======================================
In my code behind:
======================================
...
Protected WithEvents haAnchor As System.Web.UI.HtmlControls.HtmlAnchor
...

Public Sub haAnchor_Click(ByVal sender As Object, ByVal e As EventArgs)
Handles haAnchor.ServerClick
Me.Label1.Text = "HTML Anchor ServerClick fired!"
End Sub
======================================

When I put my HTMLAnchor control inside a repeater, the ServerClick event
does not fire:
=========================================
<table>
<asp:Repeater id=rpCustomers OnItemCommand="rpCustomers_ItemCommand"
EnableViewState="False" runat="server" DataSource="<%# dvwCustomerDisplays
%>">
<ItemTemplate>
<tr>
<td>
<a ID="haAnchor" OnServerClick="haAnchor_Click"
runat="server">Click
here</a>
</td>
</tr>
</ItemTemplate>
</asp:Repeater>
</table>
=====================================
In my code behind, I have the same handler as before, plus this one:
=====================================
Public Sub rpCustomers_ItemCommand(ByVal source As Object, ByVal e As
System.Web.UI.WebControls.RepeaterCommandEventArgs ) Handles
rpCustomers.ItemCommand
Me.Label1.Text = "HTML Anchor ItemCommand fired!"
End Sub
======================================


Nov 18 '05 #3
Hi Leigh,

Glad to hear you got going. We've all been caught on the small issues -
although I'm surprised the quotes would make a difference there.

BTW, you might want to offer the syntax checker suggestion to Microsoft
here:

http://lab.msdn.microsoft.com/produc...k/default.aspx

Ken
"Leigh Webber" <Le*********@discussions.microsoft.com> wrote in message
news:51**********************************@microsof t.com...
Thanks, Ken. The problem was that I had omitted the quotation marks around
the repeater's ID attribute. IOW, I had:

<asp:repeater id=rpCustomers ...

when I should have had:

<asp:repeater id="rpCustomers" ...

Sheesh -- can I please have the four hours back I spent chasing my tail on
this one? What a bonehead. :-(

Hmmm -- too bad the syntax checker doesn't pick this one up.

"Ken Cox [Microsoft MVP]" wrote:
Hi Leigh,

I'm not clear on what you're aiming to accomplish, but here's what I
managed
to do with your code:
<table border="1">
<asp:repeater id="rpCustomers"
OnItemCommand="rpCustomers_ItemCommand" EnableViewState="False"
runat="server">
<itemtemplate>
<tr>
<td>
<a id="haAnchor"
onserverclick="haAnchor_Click" runat="server">Click here</a>
</td>
</tr>
</itemtemplate>
</asp:repeater>
</table>
</form>
<p> </p>
<p>
<asp:label id="Label1" runat="server">Label</asp:label></p>

Private Sub Page_Load(ByVal sender As System.Object, _
ByVal e As System.EventArgs) Handles MyBase.Load
Dim dvwCustomerDisplays As DataView
dvwCustomerDisplays = CreateDataSource().DefaultView
rpCustomers.DataSource = dvwCustomerDisplays
rpCustomers.DataBind()
End Sub

Public Sub haAnchor_Click(ByVal sender As Object, _
ByVal e As System.EventArgs)
Dim htmlAnchor As HtmlAnchor
htmlAnchor = sender
Label1.Text = "HTML Anchor ServerClick fired!" & _
htmlAnchor.UniqueID
End Sub

Public Sub rpCustomers_ItemCommand(ByVal source As Object, _
ByVal e As System.Web.UI.WebControls.RepeaterCommandEventArgs ) _
Handles rpCustomers.ItemCommand
Response.Write(e.Item.ItemIndex.ToString)
End Sub

Function CreateDataSource() As DataTable
Dim dt As New DataTable
Dim dr As DataRow
dt.Columns.Add(New DataColumn _
("IntegerValue", GetType(Int32)))
dt.Columns.Add(New DataColumn _
("StringValue", GetType(String)))
dt.Columns.Add(New DataColumn _
("CurrencyValue", GetType(Double)))
dt.Columns.Add(New DataColumn _
("Boolean", GetType(Boolean)))
Dim i As Integer
For i = 0 To 8
dr = dt.NewRow()
dr(0) = i
dr(1) = "Item " + i.ToString()
dr(2) = 1.23 * (i + 1)
dr(3) = (i = 4)
dt.Rows.Add(dr)
Next i
Return dt
End Function 'CreateDataSource
"Leigh Webber" <Le*********@discussions.microsoft.com> wrote in message
news:61**********************************@microsof t.com...
>I have an HTMLAnchor control on my aspx page. When it's not inside a
> repeater, it works fine. When I put it inside a repeater control, the
> handler
> never gets fired. I have a handler for the htmlAnchor's ServerClick
> event
> (works when not inside a repeater), and a handler for the repeater's
> ItemCommand event. My html and vb source code is shown below, but what
> I
> think I need is a simple working example in vb.net. Can anyone help?
> ======================================
> <a ID="haAnchor" OnServerClick="haAnchor_Click" runat="server">Click
> here</a>
> ======================================
> In my code behind:
> ======================================
> ...
> Protected WithEvents haAnchor As System.Web.UI.HtmlControls.HtmlAnchor
> ...
>
> Public Sub haAnchor_Click(ByVal sender As Object, ByVal e As
> EventArgs)
> Handles haAnchor.ServerClick
> Me.Label1.Text = "HTML Anchor ServerClick fired!"
> End Sub
> ======================================
>
> When I put my HTMLAnchor control inside a repeater, the ServerClick
> event
> does not fire:
> =========================================
> <table>
> <asp:Repeater id=rpCustomers OnItemCommand="rpCustomers_ItemCommand"
> EnableViewState="False" runat="server" DataSource="<%#
> dvwCustomerDisplays
> %>">
> <ItemTemplate>
> <tr>
> <td>
> <a ID="haAnchor" OnServerClick="haAnchor_Click"
> runat="server">Click
> here</a>
> </td>
> </tr>
> </ItemTemplate>
> </asp:Repeater>
> </table>
> =====================================
> In my code behind, I have the same handler as before, plus this one:
> =====================================
> Public Sub rpCustomers_ItemCommand(ByVal source As Object, ByVal e As
> System.Web.UI.WebControls.RepeaterCommandEventArgs ) Handles
> rpCustomers.ItemCommand
> Me.Label1.Text = "HTML Anchor ItemCommand fired!"
> End Sub
> ======================================



Nov 18 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: kamaumalone | last post by:
I have a dropdownlist which lives inside of a repeater. The repeater accepts user input via textboxes and the aforementioned dropdownlist. The repeater accepts phone numbers and allows for an...
2
by: Stephen Miller | last post by:
I am using the OnItemDataBound event of Repeater control to nest a DataGrid within the Repeater. When I attempt to bind to the DataGrid using the DataSource method I get the error message "Object...
7
by: Scott Schluer | last post by:
Hi All, I have a functioning datagrid on "Page 1" that displays order information for a single order (this is for an e-commerce site). It's actually a combination of a couple datagrids to...
4
by: huzz | last post by:
I am trying to access a DropDownList control inside a repeater using ItemCommand as shown below but for some reason i can't access the DropDownList. When i step through the debug i get <undefine...
0
by: Reza Nabi | last post by:
Dear All: Banckgroud: I have a datagrid which lives inside a repeater. Which is working fine. What i need is to dyanamically set the column width of the grid (which lieves inside the repeater)....
8
by: fernandezr | last post by:
I would like to use a user control as a template inside a repeater. Some of the fields in the control should be hidden depending on whether or not there is data. I'm still a ASP .Net newbie so the...
0
by: uncensored | last post by:
Hello everyone, I'm fairly new at .Net and I have a repeater inside a repeater problem. I will attach my code to this message but basically what I am able to tell when I run my page it tells me...
1
by: champ.supernova | last post by:
Hi, I have a dropdownlist which is repeated inside a repeater. What I'm wanting is for when one instance of the dropdownlist has its selection changed, for 1) this to trigger an...
1
by: Řyvind Isaksen | last post by:
I need to know how to handle controls inside a repeater, how to send and recieve data from another page to one spesific control inside a repeater. Clue: I have a repeater that dynamicly lists...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.