Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Dynamic button problem

Status
Not open for further replies.

digimortal

Programmer
Oct 12, 2003
28
TR
I'm creating a button at runtime and It will insert the radiobuttons (from dynamic radiogroups) values to table:

But I can not implement the click event, here is my code:

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim i, j, seldate As Integer
Table3.Visible = True
SqlDataAdapter1.Fill(WorkHoursDS1)
Table3.Rows(0).Cells(0).ColumnSpan = 2
seldate = Calendar1.SelectedDate.DayOfWeek
For i = 1 To Textbox4.Text
Dim Day As New TableRow
Dim HType1 As New TableCell

Table3.Rows.Add(Day)

HType1.BackColor = HType1.BackColor.FromArgb(102, 0, 204)
HType1.ForeColor = HType1.ForeColor.White
HType1.Font.Bold = True


If seldate > 7 Then
seldate = seldate - 7
End If

Select Case seldate
Case 1
HType1.Text = i & ". Pazartesi"
Case 2
HType1.Text = i & ". Sal?"
Case 3
HType1.Text = i & ". Çar?amba"
Case 4
HType1.Text = i & ". Per?embe"
Case 5
HType1.Text = i & ". Cuma"
Case 6
HType1.Text = i & ". Cumartesi"
Case 7
HType1.Text = i & ". Pazar"
End Select

seldate = seldate + 1

Table3.Rows(i).Cells.Add(HType1)

Dim HType As New TableCell
Dim HourSelect As New RadioButtonList

HType.BackColor = HType.BackColor.FromArgb(204, 204, 255)
HType.ForeColor = HType.ForeColor.Black
HType.Font.Bold = True

HourSelect.RepeatDirection = HourSelect.RepeatDirection.Horizontal
HourSelect.CellPadding = 2
HourSelect.CellSpacing = 2
HourSelect.DataValueField = WorkHoursDS1.WorkHours.TypeIDColumn.ToString
HourSelect.DataTextField = WorkHoursDS1.WorkHours.TypeNameColumn.ToString

HourSelect.ForeColor = HourSelect.ForeColor.White
HourSelect.Font.Bold = True
HourSelect.DataSource = WorkHoursDS1.WorkHours
HourSelect.DataBind()

HType.Controls.Add(HourSelect)
Table3.Rows(i).Cells.Add(HType)

Next

Dim Send As New TableRow
Dim SendCol As New TableCell
Dim SendButton As New Button

SendButton = New Button
'Here is the Problem!!!
AddHandler SendButton.Click, AddressOf SendButton_OnClick

SendCol.BackColor = SendCol.BackColor.FromArgb(102, 0, 204)
SendCol.HorizontalAlign = HorizontalAlign.Right
SendCol.ColumnSpan = 2

i = Textbox4.Text + 1

SendCol.Controls.Add(SendButton)

SendButton.Width = Button1.Width
SendButton.Font.Bold = True
SendButton.Text = "Kaydet"

Table3.Rows.Add(Send)
Table3.Rows(i).Cells.Add(SendCol)

End Sub
'This is not running!!!
Private Sub SendButton_OnClick(ByVal sender As Object, ByVal e As System.EventArgs)
Label1.Text = "Dynamic Button Clicked"
End Sub
 
My bet is that SendButton reference is local to the Button1 subroutine, but stays on the form.

Try making SendButton global to the form, by removing only the Dim SendButton statement from the Button1_Click routine, and placing it with the global form variables.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top