User Control Problem

R

Roshawn

Hi,

I have created a web user control that acts as a numeric pager on my page.
It consists of a repeater controls and an HtmlAnchor control. Of course the
HtmlAnchor is placed in the repeater's ItemTemplate template. Just a note
that the HtmlAnchor control is not set as a server control.

In the web user control I've created an event named PagerClick. What I'm
trying to do is pass the HtmlAnchor's InnerText to the page that contains
the web user control so further processing can be done. Here's my code:

Public Class SelectedAnchorEventArgs
Inherits EventArgs
Public Text As String
End Class

Public MustInherit Class NumericPager
Inherits System.Web.UI.UserControl
Protected WithEvents Repeater2 As System.Web.UI.WebControls.Repeater
Event PagerClick(ByVal sender As Object, ByVal e As
SelectedAnchorEventArgs)

Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
End Sub

Public Function PagerNumbers() As ArrayList
'code implementation omitted, though it works great
End Function

Public Sub BindPager(ByVal arr As ArrayList)
With Me.Repeater2
.DataSource = arr
.DataBind()
End With
End Sub

Public Sub Pager_Click(ByVal sender As Object, ByVal e As EventArgs)
Dim eventinfo As New SelectedAnchorEventArgs()
eventinfo.Text = CType(sender, HtmlAnchor).InnerText
RaiseEvent PagerClick(Me, eventinfo)
End Sub
End Class

Here is my code on the host page that uses the PagerClick event of the web
user control:

Private Sub NPager_Click(ByVal sender As Object, ByVal e As
SelectedAnchorEventArgs) Handles
NPager.PagerClick
Me.ViewState("page") = e.Text
Call GetKeywordData()
End Sub

I don't know why, but the procedure on the host page doesn't work. I've
tried modifying the attributes of the HtmlAnchor. I'm not sure if I'm to
override its OnServerClick method to get things to work. I've tried
everything else, but no success.

So I've come to feet of the great ASP.NET programmers out there. Can anyone
point me in the right direction? I've been toying with this all weekend
long. Any help will be greatly appreciated.

Thanks,
Roshawn

Sorry for cross-posting :-(
 
P

Paul Glavich [MVP - ASP.NET]

Only had a quick glance at the code and I dont do VB.NEt much but have you
added your pages event handler delegate to the user controls event list
similar to what the page does. Eg. a page will have something like (sorry
for the C#) :-

this.MyEvent += new EventHandler(MyMethod);

to add the event handler delegate method. I couldn't see anywhere you are
doing this.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,994
Messages
2,570,222
Members
46,809
Latest member
moe77

Latest Threads

Top