Reputation: 291
I can't find DropdownList ,Because inside the update panel other control outside update panel can find it I using the following code:
For Each c As Control In form1.Page.Controls
findControl(c)
Next
Private Function findControl(c As Control)
For Each k As Control In c.Controls
If TypeOf k Is DropDownList Then
If CType(k, DropDownList).ID = "C1" Then
CType(k, DropDownList).SelectedItem.Value = 2
End If
findControl(k)
End If
Next
Return ""
End Function
////////////////////////////////////
<td class="combo_ghaza">
<asp:UpdatePanel ID="UPC1" runat="server">
<ContentTemplate>
<asp:DropDownList runat="server" Width="180px" ID="C1" class="combo_ghaza" EnableViewState="true" Font-Names="myFirstFont" AutoPostBack="true" OnSelectedIndexChanged="C1_SelectedIndexChanged">
</asp:DropDownList>
<asp:DropDownList ID="CS1" runat="server" Width="70px" class="combo_ghaza" InitialValue="-1" Font-Names="myFirstFont">
</asp:DropDownList>
</ContentTemplate>
</asp:UpdatePanel>
</td>
Upvotes: 0
Views: 595
Reputation: 1989
The recursive call seems to be in the wrong position, try to move it one line down
Private Function findControl(c As Control)
For Each k As Control In c.Controls
If TypeOf k Is DropDownList Then
If CType(k, DropDownList).ID = "C1" Then
CType(k, DropDownList).SelectedItem.Value = 2
End If
End If
findControl(k)
Next
Return ""
End Function
Upvotes: 1