"SLE" <in**@NOSPAM.da taworx.be> wrote...
A web user control exposes a RadioButtonList (with AutoPostBack = true)
called "Question". This control also has an embedded
RequiredFieldVa lidator control.
1. Main ASPX page is populated with several "Questions" .
2. Within the code of the main page, there is a SelectedIndexCh anged
handler for the RadioButtonList exposed by Question. The function loops through a
number of questions on the pages and hides/shows questions
(control.visibl e property) depending on answers of other questions.
All works fine until I press the submit button which forces a
Me.Validate() - if there are any errors because of unanswered questions,
the above system no longer works.
If I disable "SmartNavigatio n" everyhting works fine but I need it because
of the postbacks which cause unacceptable scrolling (d)effects...
This is a repro. The following simple example creates some questions (via a
web user control) on the main ASPX page. It demonstrates what I want to do,
i.e. if the answer to question 5 equals "1", question 6 should disappear.
Everything works fine until the submit button is invoked. From then on, I
cannot hide questions (though .Visible = False is stepped into). When
turning off smartnavigation , it works. Having smartnavigation without the
required field validator control works fine too...
1) WebForm1.aspx.v b:
Public Class WebForm1
Inherits System.Web.UI.P age
Protected WithEvents ValidationSumma ry1 As
System.Web.UI.W ebControls.Vali dationSummary
Protected WithEvents Button1 As System.Web.UI.W ebControls.Butt on
Protected WithEvents PlaceHolder1 As System.Web.UI.W ebControls.Plac eHolder
#Region " Web Form Designer Generated Code "
'This call is required by the Web Form Designer.
<System.Diagnos tics.DebuggerSt epThrough()> Private Sub
InitializeCompo nent()
End Sub
Private Sub Page_Init(ByVal sender As System.Object, ByVal e As
System.EventArg s) Handles MyBase.Init
'CODEGEN: This method call is required by the Web Form Designer
'Do not modify it using the code editor.
InitializeCompo nent()
Me.SmartNavigat ion = True
Dim i As Integer
Dim c As UserControl
For i = 1 To 10
c = New UserControl()
c = CType(LoadContr ol("WebUserCont rol1.ascx"), WebUserControl1 )
CType(c, WebUserControl1 ).InitQuestion( i)
FindControl("Pl aceHolder1").Co ntrols.Add(c)
Next
End Sub
#End Region
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
System.EventArg s) Handles MyBase.Load
'Put user code to initialize the page here
If IsPostBack Then
Dim c As UserControl
For Each c In FindControl("Pl aceHolder1").Co ntrols
If CType(c, WebUserControl1 ).QID = 5 Then
If CType(c, WebUserControl1 ).RadioButtonLi st.SelectedInde x = 0 Then
GetUserControl( 6).Visible = False
Else
GetUserControl( 6).Visible = True
End If
End If
Next
End If
End Sub
Private Function GetUserControl( ByVal questionID As Integer) As
WebUserControl1
Dim c As Control
For Each c In Me.FindControl( "PlaceHolder1") .Controls
If CType(c, WebUserControl1 ).QID = questionID Then
Return CType(c, WebUserControl1 )
End If
Next
End Function
Private Sub Button1_Click(B yVal sender As System.Object, ByVal e As
System.EventArg s) Handles Button1.Click
Me.Validate()
If Me.IsValid Then
Response.Redire ct("about
:blank ")
End If
End Sub
End Class
2) WebUserControl1 .ascx.vb:
Public MustInherit Class WebUserControl1
Inherits System.Web.UI.U serControl
Protected WithEvents Panel1 As System.Web.UI.W ebControls.Pane l
Protected WithEvents Label1 As System.Web.UI.W ebControls.Labe l
Protected WithEvents RequiredFieldVa lidator1 As
System.Web.UI.W ebControls.Requ iredFieldValida tor
Protected WithEvents RadioButtonList 1 As
System.Web.UI.W ebControls.Radi oButtonList
#Region " Web Form Designer Generated Code "
'This call is required by the Web Form Designer.
<System.Diagnos tics.DebuggerSt epThrough()> Private Sub
InitializeCompo nent()
End Sub
Private Sub Page_Init(ByVal sender As System.Object, ByVal e As
System.EventArg s) Handles MyBase.Init
'CODEGEN: This method call is required by the Web Form Designer
'Do not modify it using the code editor.
InitializeCompo nent()
Me.RadioButtonL ist1.AutoPostBa ck = True
End Sub
#End Region
Private mintQID As Integer
Public ReadOnly Property RadioButtonList () As RadioButtonList
Get
Return RadioButtonList 1
End Get
End Property
Public ReadOnly Property QID() As Integer
Get
Return mintQID
End Get
End Property
Public Sub InitQuestion(By Val QID As Integer)
mintQID = QID
Label1.Text = "Question " & mintQID.ToStrin g()
With RadioButtonList 1.Items
.Add("1")
.Add("2")
.Add("3")
End With
End Sub
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
System.EventArg s) Handles MyBase.Load
'Put user code to initialize the page here
End Sub
End Class