Products

Solutions

Resources

Partners

Community

About

New Community Website

Ordinarily, you'd be at the right spot, but we've recently launched a brand new community website... For the community, by the community.

Yay... Take Me to the Community!

Welcome to the DNN Community Forums, your preferred source of online community support for all things related to DNN.
In order to participate you must be a registered DNNizen

HomeHomeDevelopment and...Development and...Getting StartedGetting StartedGenerate Controls DynamicallyGenerate Controls Dynamically
Previous
 
Next
New Post
4/18/2017 10:01 AM
 
Hi Everyone

I will try to Generate Controls Dynamically using vb.
but i faced a problem":Unable to cast object of type 'System.Web.UI.HtmlControls.HtmlGenericControl' to type 'System.Web.UI.WebControls.TextBox'"
This Code It Work before i Upgrade FrameWork to 4.6.1
  Public Sub LoadFormValues(ByVal pCtl As WebUI.Control, ByVal ModuleId As Int32, ByVal ModuleKey As String)
            Dim ctlDiv As WebUI.Control
            For Each dCtl As DynamicControl In Me
                ctlDiv = FindControlR(controlPrefix & dCtl.CtlId, pCtl)
                If Not ctlDiv Is Nothing AndAlso ctlDiv.Controls.Count > 1 Then
                    Select Case dCtl.CtlType
                        Case SharedTypes.ControlTypes.CheckBox
                            Dim thisCtl As WebCtl.CheckBox = ctlDiv.Controls(1)
                            dCtl.ControlValue = thisCtl.Checked
                        Case SharedTypes.ControlTypes.DropDownlist
                            Dim thisCtl As WebCtl.DropDownList = ctlDiv.Controls(1)
                            dCtl.ControlValue = thisCtl.SelectedValue
                        Case SharedTypes.ControlTypes.Textbox
                            Dim thisCtl As WebCtl.TextBox = ctlDiv.Controls(1) (when debug Stop here :) )
                            dCtl.ControlValue = thisCtl.Text
                        Case SharedTypes.ControlTypes.BoundDropDownList
                            Dim thisCtl As WebCtl.DropDownList = ctlDiv.Controls(1)
                            dCtl.ControlValue = thisCtl.SelectedValue
                    End Select
                End If
            Next
        End Sub
  Private Function FindControlR(ByVal ControlName As String, ByVal pCtl As WebUI.Control) As Object
            If LCase(pCtl.ID) = LCase(ControlName) Then
                Return pCtl
            End If

            Dim ctl As WebUI.Control
            For Each ctl In pCtl.Controls
                Dim ctl2 As WebUI.Control = DirectCast(FindControlR(ControlName, ctl), WebUI.Control)
                If Not ctl2 Is Nothing Then Return ctl2
            Next
            Return Nothing
        End Function

Waiting for your guidance .....
 
New Post
4/25/2017 5:21 AM
 
it solved by change code to:
Dim thisCtl As WebCtl.TextBox = ctlDiv.Controls(1).Control(0)
 
Previous
 
Next
HomeHomeDevelopment and...Development and...Getting StartedGetting StartedGenerate Controls DynamicallyGenerate Controls Dynamically


These Forums are dedicated to discussion of DNN Platform and Evoq Solutions.

For the benefit of the community and to protect the integrity of the ecosystem, please observe the following posting guidelines:

  1. No Advertising. This includes promotion of commercial and non-commercial products or services which are not directly related to DNN.
  2. No vendor trolling / poaching. If someone posts about a vendor issue, allow the vendor or other customers to respond. Any post that looks like trolling / poaching will be removed.
  3. Discussion or promotion of DNN Platform product releases under a different brand name are strictly prohibited.
  4. No Flaming or Trolling.
  5. No Profanity, Racism, or Prejudice.
  6. Site Moderators have the final word on approving / removing a thread or post or comment.
  7. English language posting only, please.
What is Liquid Content?
Find Out
What is Liquid Content?
Find Out
What is Liquid Content?
Find Out