Lil Ms Squirrel
Feb 23rd, 2005, 09:52 AM
I have a questionnaire type web form where if the user selects a particular answer, it shows or hides a textbox for an additional description.
It all works well on my local machine, but when i try to use it from the production server, the postbacks don't seem to work. The progress bar shows it's posting back but the controls don't appear!
Anyone seen this before and know how to fix it?
Cheers
Lil Ms S
PS I know doing loads of postbacks is a bad idea, but you try telling my boss that :eek:
nemaroller
Feb 23rd, 2005, 12:32 PM
post your code (the relevant code)
Lil Ms Squirrel
Feb 24th, 2005, 02:14 AM
Okay this is the code.
The entire form is generated dynamically based a set of customised questions from the database.
It now works sporadically for some options, but not for all of them. And each time I try it, only one or two postback properly whereas on my local machine it all works perfectly:
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Dim ds As Questions
Dim question As Questions.QuestionsRow
Dim tablenames(0) As String
Try
tablenames(0) = "Questions"
If Not IsPostBack Then
ds = New Questions
If PopulateClientData() = False Then
'cancel the load because this review has already been completed
Exit Sub
End If
'populate the dataset and store in the session object
SqlHelper.FillDataset(connectionString, CommandType.StoredProcedure, "uspGetReviewQuestions", ds, tablenames)
Session("Questions") = ds
Else
Response.Write("Postback")
ds = CType(Session("Questions"), Questions)
End If
With pnlReview.Controls
'start table creation
.Add(New LiteralControl("<TABLE id='Table2' cellSpacing='1' cellPadding='1' width='100%' border='0'>"))
For Each question In ds.Questions
'add the first row with the question
.Add(New LiteralControl("<TR>"))
.Add(New LiteralControl("<TD vAlign='middle' align='left' width='85%'><FONT size='2'><STRONG>"))
.Add(New LiteralControl(question.ReviewQuestion))
If question.RequiresYesNo = True Then
'create the rfv
rfv = New RequiredFieldValidator
rfv.ErrorMessage = "Please select a value for '" & question.ReviewQuestion & "'"
rfv.ControlToValidate = "Q" & question.ReviewQuestionID
rfv.Text = "*"
rfv.Font.Bold = True
rfv.ForeColor = errorColor
.Add(rfv)
.Add(New LiteralControl(" "))
lbl = New Label
lbl.ForeColor = errorColor
lbl.Font.Bold = True
lbl.Font.Italic = True
lbl.Font.Size = fontSize
lbl.Font.Name = "verdana"
lbl.Text = "Please specify a reason: "
lbl.Visible = False
lbl.ID = "L" & question.ReviewQuestionID
.Add(lbl)
.Add(New LiteralControl("</STRONG></FONT></TD>"))
.Add(New LiteralControl("<TD vAlign='middle' align='left' width='15%'>"))
End If
'create the rbl -- always add one to the form, but hide it if requires yes/no = false
rbl = New RadioButtonList
rbl.ID = "Q" & question.ReviewQuestionID
rbl.Items.Add(New ListItem("Yes", 1))
rbl.Items.Add(New ListItem("No", 0))
rbl.RepeatColumns = 2
rbl.RepeatDirection = RepeatDirection.Horizontal
rbl.ForeColor = foreColor
rbl.Width = New Unit(100, UnitType.Percentage)
rbl.Font.Size = fontSize
rbl.AutoPostBack = True
rbl.Visible = question.RequiresYesNo
.Add(rbl)
'if the question requires a reason then add a reason box
If question.RequiresReason = True Then
'now add the textbox and label on a new row
.Add(New LiteralControl("<TR>"))
.Add(New LiteralControl("<TD vAlign='middle' align='left' width='85%'>"))
box = New TextBox
box.ID = "R" & question.ReviewQuestionID
box.ForeColor = foreColor
box.Width = New Unit(97, UnitType.Percentage)
box.MaxLength = 250
box.BackColor = backColor
box.Font.Name = fontName
box.Font.Size = fontSize
If question.RequiresYesNo = True Then box.Visible = False
.Add(box)
'add an rfv for the text box
rfv = New RequiredFieldValidator
rfv.ErrorMessage = "Please specify a reason"
rfv.ControlToValidate = "R" & question.ReviewQuestionID
rfv.Text = "*"
rfv.ForeColor = foreColor
rfv.Enabled = False
.Add(rfv)
'close the current row
.Add(New LiteralControl("<TD>"))
.Add(New LiteralControl("<TD align='left' width='15%'></TD>"))
.Add(New LiteralControl("</TR>"))
If question.RequiresYesNo = True Then
AddHandler rbl.SelectedIndexChanged, AddressOf ShowHideTextBox
Else
box.Rows = 2
box.TextMode = TextBoxMode.MultiLine
End If
End If
Next
'finally close off the table
.Add(New LiteralControl("</TABLE>"))
End With
Catch ex As Exception
RedirectError("Error populating annual review." & ex.ToString)
End Try
End Sub
Private Sub ShowHideTextBox(ByVal sender As Object, ByVal e As EventArgs)
Dim rbl As RadioButtonList = CType(sender, RadioButtonList)
Dim box As TextBox
Dim ctl As Control
Dim index As Integer
Dim lbl As Label
Dim ds As Questions
Dim view As DataView
Dim question As Questions.QuestionsRow
index = Mid(rbl.ID, 2)
For Each ctl In pnlReview.Controls
If TypeOf ctl Is TextBox Then
If ctl.ID = "R" & index Then
box = CType(ctl, TextBox)
End If
Else
If TypeOf ctl Is Label Then
If ctl.ID = "L" & index Then
lbl = CType(ctl, Label)
End If
End If
End If
Next
'find the question associated with this id
ds = CType(Session("Questions"), Questions)
view = New DataView(ds.Questions)
view.RowFilter = ds.Questions.ReviewQuestionIDColumn.ColumnName & " = " & index
If view.Count = 1 Then question = CType(view(0).Row, Questions.QuestionsRow)
If Not IsNothing(question) Then
If question.JustifyIfYes = True Then
If rbl.SelectedValue = 1 Then
box.Visible = True
lbl.Visible = True
Else
box.Visible = False
lbl.Visible = False
End If
Else
If rbl.SelectedValue = 1 Then
box.Visible = False
lbl.Visible = False
Else
box.Visible = True
lbl.Visible = True
End If
End If
End If
End Sub
Any ideas? :eek2: