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

How to get controls from a placeholder

4 Answers 230 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
Peny
Top achievements
Rank 1
Peny asked on 04 Jul 2011, 04:03 PM
Hello,

I have a placeholder inside an update panel as showing in the below Code block.
<tr>
<
td>
<
asp:UpdatePanel ID="UpdatePanel36" runat="server" UpdateMode="Conditional">
<
ContentTemplate>
<
asp:PlaceHolder runat="server" ID="Fields">
</
asp:PlaceHolder>
</
ContentTemplate>
<
Triggers>
<
asp:AsyncPostBackTrigger ControlID="DropDownList2" />
</
Triggers>
</
asp:UpdatePanel>
</
td>
</
tr>
I dynamically create some Comboboxes as showing below
.....
Dim dropDownList As DropDownList
dropDownList =
New DropDownList
dropDownList.ID = array_action_ids(i)
dropDownList.Visible =
True
dropDownList.DataSourceID =
"SqlDataSource2"
dropDownList.DataTextField =
"LEGAL_PHONE_NUMBER"
dropDownList.DataValueField =
"LEGAL_PHONE_ID"
Fields.Controls.Add(GetLiteral("<td>"))
Fields.Controls.Add(dropDownList)
Fields.Controls.Add(GetLiteral(
"</td>"))
.....

I also have a submit button.
I want to get the selected value of the dropdownlist when the button is clicked.

I tried
Dim dropdownlist_phone As DropDownList = CType(Fields.FindControl("DropDownList_Phone"), DropDownList)

but it didn't work. I also tried
Dim temp_Placeholder as Placeholder = CType(UpdatePanel36.FindControl("Fields"), Placeholder)
Dim
dropdownlist_phone As DropDownList = CType(temp_Placeholder.FindControl("DropDownList_Phone"), DropDownList)

but it didnt either work.
The controls of the Fields placeholder seems to be nothing in both approaches.

Could you please help me?

Thanks in advance,
Peny

4 Answers, 1 is accepted

Sort by
0
Prangadj
Top achievements
Rank 1
answered on 04 Jul 2011, 05:12 PM
Peny, you mistaken ms asp.net forums with telericks? No telerick controls in your code, ask other place.
0
Peny
Top achievements
Rank 1
answered on 05 Jul 2011, 08:06 AM
Hello ,

I am sorry for the wrong post ...

I am new in asp.net and telerik programming, so I didnt exactly where to ask.
Is there a way to do this with telerik controls?

Regards,
Peny
0
Prangadj
Top achievements
Rank 1
answered on 05 Jul 2011, 08:30 AM
If this does not work with MS controls, it won't work with telericks as your logic is not good. Make sure you create dropdowns on page init or page load and no later. May also read this asp.net tutorial:
http://www.aspnettutorials.com/tutorials/controls/control-dym-aspnet2-csharp.aspx

Prangadj
0
Peny
Top achievements
Rank 1
answered on 05 Jul 2011, 08:43 AM
Hello Prangadj,

I really appreciate your help!!!

I cannot create the controls on page init because the controls creation depends on the value of an other dropdown list and i dont know from the beggining which controls should be created.

Peny
Tags
General Discussions
Asked by
Peny
Top achievements
Rank 1
Answers by
Prangadj
Top achievements
Rank 1
Peny
Top achievements
Rank 1
Share this question
or