This is a migrated thread and some comments may be shown as answers.

Dynamic controls and ajax

1 Answer 92 Views
Ajax
This is a migrated thread and some comments may be shown as answers.
tkoc
Top achievements
Rank 2
tkoc asked on 14 Sep 2009, 10:32 PM
Hi
i have a script there then you select 2 days in 2 RadDatePicker
updates a table with timepickers
    Protected Sub RadDatePicker2_SelectedDateChanged(ByVal sender As ObjectByVal e As Telerik.Web.UI.Calendar.SelectedDateChangedEventArgs) Handles RadDatePicker2.SelectedDateChanged  
        Dim Days As Integer 
        If RadDatePicker2.SelectedDate.Value.Subtract(RadDatePicker1.SelectedDate.Value).Days >= 0 Then 
            Days = RadDatePicker2.SelectedDate.Value.Subtract(RadDatePicker1.SelectedDate.Value).Days  
            For i = 0 To Days Step 1  
                Dim row As New TableRow  
                Dim cell As New TableCell  
                cell.Text = RadDatePicker1.SelectedDate.Value.AddDays(i)  
                row.Cells.Add(cell)  
                cell = New TableCell  
                Dim timePicker As New Telerik.Web.UI.RadTimePicker  
                timePicker.ID = "TimePickerA" & i  
                timePicker.Skin = "Black" 
                cell.Controls.Add(timePicker)  
                row.Cells.Add(cell)  
                timePicker = New Telerik.Web.UI.RadTimePicker  
                timePicker.ID = "TimePickerB" & i  
                timePicker.Skin = "Black" 
                cell.Controls.Add(timePicker)  
                row.Cells.Add(cell)  
                EventDates.Rows.Add(row)  
            Next 
        End If 
    End Sub 

the problem is then i use a button to submit the form how do i get access to my RadTimePicker  controls
then i look in the table it is emtry
the dynamic create rows disapers

1 Answer, 1 is accepted

Sort by
0
Sebastian
Telerik team
answered on 17 Sep 2009, 08:55 AM
Hi tkoc,

Creating server controls inside postback event handler is not proper approach since this is a late stage in the page lifecycle to create controls (their viewstate/lifecycle will be corrupted and they will disappear on subsequent postbacks). You will experience the same behavior with regular MS Button or Calendar for example if you create them in the same way.

Please revise your logic to address the issue. After that, to locate the controls after postback, use the FindControl(id) method of the framework by passing their ids as argument.

Best regards,
Sebastian
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
Tags
Ajax
Asked by
tkoc
Top achievements
Rank 2
Answers by
Sebastian
Telerik team
Share this question
or