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

OnSelectedIndexChanged Advanced Edit Form

2 Answers 65 Views
Scheduler
This is a migrated thread and some comments may be shown as answers.
bhenke
Top achievements
Rank 1
bhenke asked on 21 Feb 2015, 12:48 AM
Hello,

I have followed the example shown in this article (http://www.telerik.com/support/kb/aspnet-ajax/scheduler/details/implement-related-radcombobox-controls-in-the-advanced-form)  to add two Rad combo boxes to the appointment advanced edit form.  In my case I need to have second combo box load based on the selection of the first combo box.  

I also have code in the parent page FormCreated event to set the default value of the first combo box when the form is shown which is as follows:

                   '--- check for insert / edit mode
                    Select Case e.Container.Mode

                        Case SchedulerFormMode.AdvancedEdit         '--- edit mode
                            '--- fall through

                        Case SchedulerFormMode.AdvancedInsert       '--- insert mode

                            '--- for insert mode we want to select the user in the drop down to match this user

                            '--- get a reference to the drop down
                            cboUser = TryCast(e.Container.Controls(1).FindControl("cboUser"), RadComboBox)

                            '--- set the default user to this user
                            cboUser.SelectedValue = mobjAppointment.UserKey

                    End Select

What I have noticed is happening is that the FIRST time the advanced form is shown the OnSelectedIndexChanged event does NOT fire for the first combo box.  However, upon subsequent inserts / edits the event DOES fire.  If I comment out the code above in the FormCreated event, the OnSelectedIndexChanged event fires the first time as well.

So there appears to be an issue when setting the selected value property of a combo box on the advanced edit form and the OnSelectedIndexChanged event.  I need the code above to set a default value (by user) in the first combo box.  I'm not sure how to work around this.

Thank you.

2 Answers, 1 is accepted

Sort by
0
bhenke
Top achievements
Rank 1
answered on 21 Feb 2015, 01:32 AM
Well I have figured out the issue.

The FormCreated event gets called ANY time there is a postback on the advanced edit form.  Therefore my code was cancelling out the event by resettting the selected value each time.

I already have some kludged code in there from another Telerik article to detect the save and cancel button click events.  I guess that must be extended now for any event but the first time the form is shown.
0
bhenke
Top achievements
Rank 1
answered on 21 Feb 2015, 01:43 AM
Just so no one else spends hours on this problem I came up with the following solution:

a)  I added a hidden field on the parent form called 'commandFlag'

b)  In the FormCreating event of the scheduler I set the 'commandFlag' to 'PageLoad'

c)  In the FormCreated event of the scheduler I consult the commandFlag.value property.  If it's 'PageLoad' then I know I'm on the Page_Load event from the child control so I can set the combo box selected value

d)  On subsequent clicks of the combo box the FormCreated event will fire but NOT the FormCreating event.  The commandFlag value is then clear so the code that should only fire on page load will get executed once.  This has the effect of not messing up the OnSelectedIndexChanged events on the advanced form
Tags
Scheduler
Asked by
bhenke
Top achievements
Rank 1
Answers by
bhenke
Top achievements
Rank 1
Share this question
or