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