Products

Solutions

Resources

Partners

Community

Blog

About

QA

Ideas Test

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

HomeHomeUsing DNN Platf...Using DNN Platf...Skins, Themes, ...Skins, Themes, ...[DNN7] Can't find dinamically created controls[DNN7] Can't find dinamically created controls
Previous
 
Next
New Post
3/6/2013 1:07 PM
 

Hello.

I am new to DNN. I know i can do this with a module, bue i can't do it this time, so please, help me solve this:

I have a skin with some vb code in it, like this:

--------------------------------------------------------------------------------
<%@ Control language="vb" AutoEventWireup="false" Explicit="True" Inherits="DotNetNuke.UI.Skins.Skin" %>
<%@ Register TagPrefix="dnn" TagName="USER" Src="~/Admin/Skins/User.ascx" %>
<style>
body {background-image:none; background-color:transparent;}
</style>
<div style="float:left; width:840px; height:460px; border:30px solid white; overflow:hidden;">
<!-- Questionário -->

<div style="float:left; width:420px; height:335px;" id="divPerguntas" runat="server"></div>
<div style="float:left; width:420px; height:75px;"><asp:ImageButton ImageUrl="/Portals/_default/Skins/AdWin/img/Enviar.png" id="imgEnviar" runat="server" style="cursor:pointer;" /></div>

<script runat="server">
    Protected Sub EnviarClick() Handles imgEnviar.Click
        
        Dim conexao As SqlConnection
        Dim comando As SqlCommand
        Dim myReader As SqlDataReader
        Dim sql As String
        
        sql = "SELECT S.SurveyID, SO.SurveyOptionID FROM AdWin_Demo.dbo.Surveys S INNER JOIN AdWin_Demo.dbo.SurveyOptions SO ON S.SurveyID = SO.SurveyID WHERE S.VideoId = " + Request.QueryString("id") + " ORDER BY S.ViewOrder, SO.ViewOrder"
        conexao = New SqlConnection(##connectionstring##)
        conexao.Open()
        comando = New SqlCommand(sql, conexao)

        myReader = comando.ExecuteReader
        
        If myReader.HasRows Then
            Dim dt As New DataTable
            dt.Load(myReader)
            Dim SurveyID As Integer = 0
            Dim FirstQuestion As Boolean = True
            Dim checkedGroup As Boolean = False
            Dim insertList As New DataTable
            Dim ColumnIDSurveyOption As New DataColumn("c", GetType(Integer))
            insertList.Columns.Add(ColumnIDSurveyOption)
            Dim row As DataRow
            
            
            For Each dr As DataRow In dt.Rows
                If FirstQuestion Then
                    SurveyID = dr("SurveyID")
                    FirstQuestion = False
                End If
                If SurveyID <> dr("SurveyID") Then
                    SurveyID = dr("SurveyID")
                    checkedGroup = False
                End If
                If SurveyID = dr("SurveyID") And checkedGroup = False Then
                    Dim radiobuttonToCheck As RadioButton = FindControl(dr("SurveyOptionID").ToString())
                    If radiobuttonToCheck.Checked Then
                        checkedGroup = True
                        row = insertList.NewRow()
                        row("insertList") = dr("SurveyOptionID")
                        insertList.Rows.Add(row)
                    End If
                End If
            Next
            
            If checkedGroup = True Then
                Dim dnnUserCtrl As New DotNetNuke.Entities.Users.UserController
                For Each dr As DataRow In insertList.Rows
                    sql = "INSERT INTO AdWin_Demo.dbo.Adwin_RespostasDadas (IDUser, SurveyOptionID) SELECT " & dnnUserCtrl.GetCurrentUserInfo.UserID & ", " & dr("SurveyOptionID").ToString()
                    comando = New SqlCommand(sql, conexao)
                    myReader = comando.ExecuteReader
                Next
            Else
                Response.Write("Nao respondeste a tudo")
            End If
        End If

        myReader.Close()
        conexao.Close()
        
        
    End Sub
    Protected Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs) Handles Me.Load

        'If Not Page.IsPostBack Then

            
        Dim conexao As SqlConnection
        Dim comando As SqlCommand
        Dim myReader As SqlDataReader
        Dim sql As String

        sql = "SELECT S.SurveyID, S.Question, SO.OptionName, SO.SurveyOptionID FROM AdWin_Demo.dbo.Surveys S INNER JOIN AdWin_Demo.dbo.SurveyOptions SO ON S.SurveyID = SO.SurveyID WHERE S.VideoId = " + Request.QueryString("id") + " ORDER BY S.ViewOrder, S.SurveyID, SO.ViewOrder"
        conexao = New SqlConnection(##connectionstring##)
        conexao.Open()
        comando = New SqlCommand(sql, conexao)

        myReader = comando.ExecuteReader

    
        If myReader.HasRows Then
            Dim dt As New DataTable
            dt.Load(myReader)
            Dim SurveyID As Integer = 0
            Dim FirstQuestion As Boolean = True
            Dim ActualDiv As System.Web.UI.HtmlControls.HtmlGenericControl
       
            For Each dr As DataRow In dt.Rows
                If SurveyID = dr("SurveyID") Then
                        
                    Dim rb As New RadioButton
                    rb.GroupName = "Group" & SurveyID.ToString()
                    rb.ID = dr("SurveyOptionID").ToString()
                    rb.Text = dr("OptionName").ToString()
                    ActualDiv.Controls.Add(rb)
                    ActualDiv.Controls.Add(New LiteralControl("<br/>"))
                        
                Else
                    SurveyID = dr("SurveyID")
       
                    If FirstQuestion = False Then
                        Dim hr2 As New HtmlGenericControl("hr")
                        divPerguntas.Controls.Add(hr2)
                    End If
                        
                    Dim div As New System.Web.UI.HtmlControls.HtmlGenericControl("DIV")
                    div.Style.Add("float", "left")
                    div.Style.Add("width", "400px")
                    div.Style.Add("color", "#777")
                    div.Style.Add("font-size", "11px")
                    div.Style.Add("line-height", "15px")
                    divPerguntas.Controls.Add(div)
                    ActualDiv = div
               
                    ActualDiv.InnerText = dr("Question").ToString()
                    ActualDiv.Controls.Add(New LiteralControl("<br/>"))
                    
                    Dim rb As New RadioButton
                    rb.GroupName = "Group" & SurveyID.ToString()
                    rb.ID = dr("SurveyOptionID").ToString()
                    rb.Text = dr("OptionName").ToString()
                    ActualDiv.Controls.Add(rb)
                    ActualDiv.Controls.Add(New LiteralControl("<br/>"))
               
                    FirstQuestion = False
                End If
            Next
            Dim hr As New HtmlGenericControl("hr")
            divPerguntas.Controls.Add(hr)
        End If

        myReader.Close()
        conexao.Close()

    End Sub
</script>
--------------------------------------------------------------------------------

So, when i click the imagebutton, it does a postback, and the controls appear again, with the same checked state. But if i do this line of code, i gives me an error. It can't find the control, i think.

--------------------------------------------------------------------------------
Dim radiobuttonToCheck As RadioButton = FindControl(dr("SurveyOptionID").ToString())
--------------------------------------------------------------------------------

Can you help me?

Thanks,
Diogo

 
New Post
3/7/2013 1:21 PM
 
I would run DB the code on page databind, I'm guessing the dynamic control just has not been created yet.
 
Previous
 
Next
HomeHomeUsing DNN Platf...Using DNN Platf...Skins, Themes, ...Skins, Themes, ...[DNN7] Can't find dinamically created controls[DNN7] Can't find dinamically created controls


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