By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
443,983 Members | 1,582 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 443,983 IT Pros & Developers. It's quick & easy.

HTMLAnchor inside a repeater

P: n/a
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
Share this Question
Share on Google+
3 Replies


P: n/a
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

P: n/a
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

P: n/a
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 discussion thread is closed

Replies have been disabled for this discussion.