Calling Event Handlers Inside Custom Control

Discussion in 'ASP .Net' started by mike.gilmore, Feb 2, 2006.

  1. mike.gilmore

    mike.gilmore Guest

    Hi,

    I've created a custom control that contains a collection of link
    buttons (PagingControl.vb). I want an event to fire when the link
    button is clicked.

    The event handler is located in my primary asp.net file
    (ShowData.aspx). However, when I attempt to compile my class file, I
    get an error because the event the link button is attempting to wire to
    doesn't exist.

    Unfortunately, my fix isn't as simple as moving my event handler from
    ShowData.aspx to the class because that function class another function
    local to the page.

    Ideally I want my PagingControl.vb file to become part of my control
    library and accessible to all of my different web applications. The
    abbreviated code for the two files is shown below.

    Thanks in advance,

    Mike

    ShowData.aspx

    Public Sub ChangePage(Sender as Object, e as CommandEventArgs)
    lblClickValue = "It worked! " & e.CommandArgument
    End Sub
    <Paging:pagingControlLabel
    id="lblPaging"
    width="100%"
    Runat="Server"/>

    <br/>

    <asp:Label
    id="lblClickValue"
    runat="server"/>

    PagingControls.vb

    Dim objLb as LinkButton

    For loop = start_page to end_page

    objLb = New LinkButton
    objLb.Text = loop
    objLb.CommandName = "lb" & loop
    objLb.CommandArgument = loop

    addHandler objLb.Command, AddressOf ChangePage

    Next
     
    mike.gilmore, Feb 2, 2006
    #1
    1. Advertisements

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 (here). After that, you can post your question and our members will help you out.