button click event

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Hi, All,

I create button in the code ( Dim Button as new Button), not using button
web component (means not drap button and drop it ont he webform), after that
I try to use button_click event, it is not work, anyone can tell how to use
button click event ?

Thanks in advance,
Martin
 
Hi, All,

I create button in the code ( Dim Button as new Button), not using button
web component (means not drap button and drop it ont he webform), after that
I try to use button_click event, it is not work, anyone can tell how to use
button click event ?

Thanks in advance,
Martin

AddHandler

Thanks,

Seth Rowe
 
Hi, Seth Rowe,

could you give sample on how to use addhandler,

Thanks,
martin

Private Sub Form_Load(sender As Object, e As EventArgs)
Dim btn as new Button()
AddHandler btn.Click, AddressOf Button_Click
End Sub

Private Sub Button_Click(sender As Object, e As EventArgs)
' Do something useful
End Sub

Thanks,

Seth Rowe
 
Thank you! Seth Rowe

What I want to do is let user click each button to pop up message which is
related to StatusDesc field of Sysstat Table, the message is dynamic. The
problem (look at code below) is StatusDesc message is overwritten by next
loop, so how to keep statusDesc message for each button?

The Code like:
---------------------------------------------------
Pub Class _Default
Dim StatusDesc As String

Private Sub Form_Load(sender As Object, e As EventArgs)

For Each row In dtSysstat.Rows ' loop each record of sysstat table
Dim button As New Button ' create button for each row

btnText = Trim(row.Item("ButtonName")) ' get ButtonName
from table
StatusDesc = Trim(row.Item("StatusDesc").ToString) 'get
StatusDesc

button.Text = btnText
panel.Controls.Add(button)

' add click event to button
AddHandler button.Click, AddressOf Button_click
End Sub

Private Sub Button_Click(sender As Object, e As EventArgs)
MsgBox(StatusDesc)
End Sub

End Class
 
martin1 said:
Thank you! Seth Rowe

What I want to do is let user click each button to pop up message which is
related to StatusDesc field of Sysstat Table, the message is dynamic. The
problem (look at code below) is StatusDesc message is overwritten by next
loop, so how to keep statusDesc message for each button?

The Code like:
---------------------------------------------------
Pub Class _Default
Dim StatusDesc As String

Private Sub Form_Load(sender As Object, e As EventArgs)

For Each row In dtSysstat.Rows ' loop each record of sysstat table
Dim button As New Button ' create button for each row

btnText = Trim(row.Item("ButtonName")) ' get ButtonName
from table
StatusDesc = Trim(row.Item("StatusDesc").ToString) 'get
StatusDesc

button.Text = btnText
panel.Controls.Add(button)

' add click event to button
AddHandler button.Click, AddressOf Button_click
End Sub

Private Sub Button_Click(sender As Object, e As EventArgs)
MsgBox(StatusDesc)
End Sub

End Class
------------------------------------------------


Thank you again,
Martin

When you create the button, set btn.tag = StatusDesc. Then when you handle
the click event you can cast the sender to a button and retrieve the tag as
the description.

Hope this helps

Lloyd Sheen
 
Hi,

Is there any way we can use mouse-over-button event instead button-click
event? What i want to do is instead let user click button to pop up message i
let user put mouse over button and then auto-pop up message?

Thanks,
Martin
 
Back
Top