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

loop through controls - control type

3 Answers 234 Views
Input
This is a migrated thread and some comments may be shown as answers.
kyle goodfriend
Top achievements
Rank 2
kyle goodfriend asked on 15 Jan 2009, 02:37 AM
I have a form that loops through the controls and builds a message off the input for an email.  I added some RADinput controls , and they don't appear to be found.  I can't figure out how to cast them either.  Here is an excerpt:
    <tr> 
    <td>Contact</td><td
        <telerik:RadComboBox ID="cboContact" runat="server" Skin="Outlook" Width="200px"
        <Items> 
        <telerik:RadComboBoxItem Text="Rental Manager" Selected="true" Value="1" /> 
        <telerik:RadComboBoxItem Text="Commanding Officer"  Value="2"/> 
        <telerik:RadComboBoxItem Text="Auxiliary President" Value="3" /> 
        <telerik:RadComboBoxItem Text="Membership Officer" Value="4" /> 
        <telerik:RadComboBoxItem Text="Service Officer" Value="5" /> 
        </Items> 
        </telerik:RadComboBox> 
    </td> 
    </tr> 
    <tr> 
    <td>Name</td><td><telerik:radtextbox Width="195px" id="txtName" runat="server" Label="" EmptyMessage="Your Name" Skin="Outlook" InvalidStyleDuration="100" LabelCssClass="radLabelCss_Outlook"</telerik:radtextbox></td
    </tr> 
  
  
  
    <tr> 
    <td>Phone Number</td><td><telerik:radmaskedtextbox skin="Outlook" runat="server" id="txtPhoneNumber" Mask="#########" EmptyMessage="" DisplayMask="###-##-####" DisplayPromptChar=" " /></td
    </tr> 
    <tr> 
    <td>Address</td><td><telerik:radtextbox Width="300px" id="txtAddress" runat="server" TextMode="MultiLine" Label="" EmptyMessage="Your Address" Skin="Outlook"></telerik:radtextbox></td
    </tr> 
    <tr> 
 


Code Behind on a button click:
            'build message body 
            Dim pnl As Control = Master.FindControl("form1").FindControl("contentplaceholder1").FindControl("pnlForm") '.FindControl("pnlForm") 
            Dim sMessageResponse As String = "" 
            For Each ctrl As Control In pnl.Controls 
                If TypeOf ctrl Is TextBox Then 
                    sMessageResponse += replaceText(ctrl.ID) & ":  " & DirectCast(ctrl, TextBox).Text & vbCrLf & vbCrLf 
                ElseIf TypeOf ctrl Is CheckBox Then 
                    sMessageResponse += replaceText(DirectCast(ctrl, CheckBox).Text) & ":  " & Replace(Replace(DirectCast(ctrl, CheckBox).Checked, "False", "No"), "True", "Yes") & vbCrLf & vbCrLf 
                ElseIf TypeOf ctrl Is DropDownList Then 
                    sMessageResponse += (replaceText(ctrl.ID) & ":  " & DirectCast(ctrl, DropDownList).SelectedIndex & vbCrLf) 
                ElseIf TypeOf ctrl Is RadioButtonList Or TypeOf ctrl Is RadioButtonList Then 
                    sMessageResponse += replaceText(ctrl.ID) & ":  " & DirectCast(ctrl, RadioButtonList).SelectedValue & vbCrLf & vbCrLf 
                Else 
                End If 
                '            sMessageResponse += vbCrLf 
            Next 
 
            Mailmsg.Body = sMessageResponse 
 
 
Prior to the RadInput controls, this worked perfectly.  I need to add an elseIF for the rad controls - I am using a radtextbox and a radmaskedtextbox.  I guess I am looking for DirectCast(ctrl, ?????).Text.


3 Answers, 1 is accepted

Sort by
0
Rosen
Telerik team
answered on 15 Jan 2009, 07:15 AM
Hi kyle goodfriend,

The easiest way to get the text property of RadTextBox and RadMaskTextBox in a generic way will be to check if the control is an instance of RadInputControl (the base class for both) and use its Text property.

All the best,
Rosen
the Telerik team

Check out Telerik Trainer, the state of the art learning tool for Telerik products.
0
kyle goodfriend
Top achievements
Rank 2
answered on 15 Jan 2009, 12:51 PM
When I use that, it tells me it is undefined.

DirectCast(ctrl, radinputcontrol).Text
0
Accepted
Rosen
Telerik team
answered on 15 Jan 2009, 02:31 PM
Hello kyle goodfriend,

Can you please check if you have the Telerik.Web.UI namespace imported in your class file?

Best wishes,
Rosen
the Telerik team

Check out Telerik Trainer, the state of the art learning tool for Telerik products.
Tags
Input
Asked by
kyle goodfriend
Top achievements
Rank 2
Answers by
Rosen
Telerik team
kyle goodfriend
Top achievements
Rank 2
Share this question
or