Share via

Reference UserControl handler from Page form codebehind file

peter liles 556 Reputation points
2022-02-19T16:46:03.567+00:00

I have changed loading UserControl from declaration in page to codebehind file but now i cannot access the imagebutton handler event?

'This is Click event definition for UserControl control.
    Public Event Click As SlideShowClick

    Public Delegate Sub SlideShowClick(ByVal sender As Object, ByVal e As SlideShowImageEventArgs)


    Protected Sub imgSlideShow_Click(ByVal sender As Object, ByVal e As ImageClickEventArgs)
        RaiseEvent Click(Me, New SlideShowImageEventArgs(CType(sender, ImageButton), e.X, e.Y))
    End Sub



Now loaded in Codebehind

            Dim uc As ASP.WebUserControl2 = CType(Page.LoadControl(controlPath), ASP.WebUserControl2)


**uc.SlideShowClick = "SlideShow1_Click"**

the error states that this is a type and cannot be used as an expression
Developer technologies | ASP.NET Core | Other

3 answers

Sort by: Most helpful
  1. Yijing Sun-MSFT 7,106 Reputation points
    2022-02-23T09:37:45.007+00:00

    Hi @peter liles ,
    You could use AddHandler.Just like this:
    aspx:

     Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load  
            AddHandler SlideShow1.Click, AddressOf SlideShow1_Click  
        End Sub  
    

    user control:

       Public Delegate Sub SlideShowClick(ByVal sender As Object, ByVal e As SlideShowImageEventArgs)  
        Public Event Click As SlideShowClick  
        Public Sub imgSlideShow_Click(ByVal sender As Object, ByVal e As ImageClickEventArgs)  
            RaiseEvent Click(Me, New SlideShowImageEventArgs(CType(sender, ImageButton), e.X, e.Y))  
        End Sub  
    

    Best regards,
    Yijing Sun


    If the answer is helpful, please click "Accept Answer" and upvote it.

    Note: Please follow the steps in our  documentation  to enable e-mail notifications if you want to receive the related email notification for this thread.

    Was this answer helpful?

    0 comments No comments

  2. peter liles 556 Reputation points
    2022-02-23T00:20:16.907+00:00

    How i resolved it was to add a handler to the page that reference the event.
    I did try to send all relevant code but unfortunately it wont allow html code? and when i attempt sending a txt file it fails?
    I am trying to build a slider from horizontal datalist. I am wondering if you may know about any available example scripts other than the popular JQUERY type. They appear to be an essential feature today.

    Thanks for your support.

    Was this answer helpful?

    0 comments No comments

  3. Yijing Sun-MSFT 7,106 Reputation points
    2022-02-21T06:14:19.4+00:00

    Hi @peter liles ,

    uc.SlideShowClick = "SlideShow1_Click"

    As I know,it can't use this in vb. Could you post all reference codes to us?
    Best regards,
    Yijing Sun


    If the answer is helpful, please click "Accept Answer" and upvote it.

    Note: Please follow the steps in our  documentation  to enable e-mail notifications if you want to receive the related email notification for this thread.

    Was this answer helpful?

    0 comments No comments

Your answer

Answers can be marked as 'Accepted' by the question author and 'Recommended' by moderators, which helps users know the answer solved the author's problem.