Dynamic controls and ajax

2 posts, 0 answers
  1. tkoc
    tkoc avatar
    1 posts
    Member since:
    May 2007

    Posted 14 Sep 2009 Link to this post

    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)  
                    cell = New TableCell  
                    Dim timePicker As New Telerik.Web.UI.RadTimePicker  
                    timePicker.ID = "TimePickerA" & i  
                    timePicker.Skin = "Black" 
                    timePicker = New Telerik.Web.UI.RadTimePicker  
                    timePicker.ID = "TimePickerB" & i  
                    timePicker.Skin = "Black" 
            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
  2. Sebastian
    Sebastian avatar
    9934 posts

    Posted 17 Sep 2009 Link to this post

    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,
    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.
Back to Top