locked
Add Right Click Handler for Dynamically Created Button in a Web form RRS feed

  • Question

  • User-786564416 posted

    I have made the following to add button dynamically according to the database table to a panel control. However, I added a Click event handler for these created button. However, I need to add a right click event handler also.

    queryString = "SELECT DISTINCT KeyTag FROM PostingsTags WHERE (RefNo=@LID)"
                GetPostingTags = New SqlCommand(queryString, connection)
                GetPostingTags.Parameters.Add("@LID", SqlDbType.NVarChar)
                GetPostingTags.Parameters("@LID").Value = LetterID
                PostingTagsReader = GetPostingTags.ExecuteReader()
    
                If PostingTagsReader.HasRows Then
                    Do While PostingTagsReader.Read()
    
                        If IsDBNull(PostingTagsReader(0)) = False Then
                            BtnIx = BtnIx + 1
                            Dim BtnTxt As String = PostingTagsReader(0)
                            Dim BtnWidth As Integer = Len(PostingTagsReader(0)) * 10
                            Dim BtnCtrl As New Button
                            BtnCtrl.ID = "Btn" & BtnIx
                            BtnCtrl.Width = BtnWidth
                            BtnCtrl.Text = BtnTxt
                            BtnCtrl.CssClass = "DynaBtn"
                            AddHandler BtnCtrl.Click, AddressOf btnDynamic_Click
                            Panel1.Controls.Add(BtnCtrl)
                        End If
                    Loop
                    PostingTagsReader.Close()
                End If

    Howe to add the a right click event handler?

    Monday, January 28, 2019 9:27 PM

All replies

  • User-943250815 posted

    There is no such event on Asp:Button.
    Perhaps with some help of javascript you can get desired result

    Monday, January 28, 2019 11:21 PM
  • User-786564416 posted

    So how to do it with Java script?

    Monday, January 28, 2019 11:30 PM
  • User-474980206 posted
    You should google to learn the trade offs for different techniques. The two most common are mouseup or context menu event. You’re current click event, is really a post back with a button name. The server generates the fake click event. You will have decide what to do with the JavaScript event triggered by the right click. Make an Ajax call, do a form post with a hidden field to I’d the right click,
    Tuesday, January 29, 2019 6:44 AM