click event of button not working when created dynamically in code behind

2 posts, 0 answers
  1. Valentijn
    Valentijn avatar
    21 posts
    Member since:
    Sep 2010

    Posted 05 Sep 2011 Link to this post

    hi

    It seems that when creating the button control in code behind, the click event never gets fired, or am i doing something wrong? Here's the code

    Dim

     

     

    btn As New RadButton

    btn.ButtonType =

     

    RadButtonType.LinkButton

    btn.EnableEmbeddedSkins =

     

    False

    btn.Skin = Common.

     

    Constants.SkinDefault

    btn.CausesValidation =

     

    False

    btn.Text = Common.Resources.

     

    Messages.RibbonVergaderingen

    btn.CommandArgument = Common.PadNaarVergaderingenLijstPagina

     

    AddHandler btn.Click, AddressOf btn_Click


    Private

     

     

    Sub btn_Click(ByVal sender As Object, ByVal e As EventArgs)

     

    Me.Presenter.Model.RefererUrl = DirectCast(sender, RadButton).CommandArgument


    end sub
  2. Shinu
    Shinu avatar
    17764 posts
    Member since:
    Mar 2007

    Posted 05 Sep 2011 Link to this post

    Hello Valentijn,

    Please try creating the control in the PageInit method which worked as expected at my end.
    VB.Net:
    Protected Sub Page_Init(sender As Object, e As System.EventArgs)
        Dim btn As New RadButton()
        btn.Text = "New Btn"
        btn.ButtonType = RadButtonType.LinkButton
        btn.EnableEmbeddedSkins = False
        btn.Click += New EventHandler(btn_Click)
        form1.Controls.Add(btn)
    End Sub

    Thanks,
    Shinu.
  3. UI for ASP.NET Ajax is Ready for VS 2017
Back to Top