SmartNavigation + AutoPostBack

Discussion in 'ASP .Net' started by SLE, Dec 9, 2003.

  1. SLE

    SLE Guest

    A web user control exposes a RadioButtonList (with AutoPostBack = true)
    called "Question". This control also has an embedded RequiredFieldValidator
    control.

    1. Main ASPX page is populated with several "Questions".
    2. Within the code of the main page, there is a SelectedIndexChanged handler
    for the RadioButtonList exposed by Question. The function loops through a
    number of questions on the pages and hides/shows questions (control.visible
    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 "SmartNavigation" everyhting works fine but I need it because
    of the postbacks which cause unacceptable scrolling (d)effects...

    Any clues?


    Thanks,
    SLE
    SLE, Dec 9, 2003
    #1
    1. Advertising

  2. SLE

    JL Guest

    Last time i used smartnavigation it was buggy.

    I use a modified version of this javascript instead:

    http://groups.google.ca/groups?hl=f...ameeg0$nlp$1$&rnum=3

    JL



    "SLE" <> wrote in message
    news:...
    > A web user control exposes a RadioButtonList (with AutoPostBack = true)
    > called "Question". This control also has an embedded

    RequiredFieldValidator
    > control.
    >
    > 1. Main ASPX page is populated with several "Questions".
    > 2. Within the code of the main page, there is a SelectedIndexChanged

    handler
    > for the RadioButtonList exposed by Question. The function loops through a
    > number of questions on the pages and hides/shows questions

    (control.visible
    > 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 "SmartNavigation" everyhting works fine but I need it because
    > of the postbacks which cause unacceptable scrolling (d)effects...
    >
    > Any clues?
    >
    >
    > Thanks,
    > SLE
    >
    >
    JL, Dec 9, 2003
    #2
    1. Advertising

  3. SLE

    SLE Guest

    "SLE" <> wrote...
    > A web user control exposes a RadioButtonList (with AutoPostBack = true)
    > called "Question". This control also has an embedded

    RequiredFieldValidator
    > control.
    >
    > 1. Main ASPX page is populated with several "Questions".
    > 2. Within the code of the main page, there is a SelectedIndexChanged

    handler
    > for the RadioButtonList exposed by Question. The function loops through a
    > number of questions on the pages and hides/shows questions

    (control.visible
    > 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 "SmartNavigation" 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.vb:

    Public Class WebForm1
    Inherits System.Web.UI.Page
    Protected WithEvents ValidationSummary1 As
    System.Web.UI.WebControls.ValidationSummary
    Protected WithEvents Button1 As System.Web.UI.WebControls.Button
    Protected WithEvents PlaceHolder1 As System.Web.UI.WebControls.PlaceHolder

    #Region " Web Form Designer Generated Code "

    'This call is required by the Web Form Designer.
    <System.Diagnostics.DebuggerStepThrough()> Private Sub
    InitializeComponent()

    End Sub

    Private Sub Page_Init(ByVal sender As System.Object, ByVal e As
    System.EventArgs) Handles MyBase.Init
    'CODEGEN: This method call is required by the Web Form Designer
    'Do not modify it using the code editor.
    InitializeComponent()

    Me.SmartNavigation = True

    Dim i As Integer
    Dim c As UserControl

    For i = 1 To 10
    c = New UserControl()
    c = CType(LoadControl("WebUserControl1.ascx"), WebUserControl1)
    CType(c, WebUserControl1).InitQuestion(i)

    FindControl("PlaceHolder1").Controls.Add(c)
    Next
    End Sub

    #End Region

    Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
    System.EventArgs) Handles MyBase.Load
    'Put user code to initialize the page here
    If IsPostBack Then
    Dim c As UserControl
    For Each c In FindControl("PlaceHolder1").Controls
    If CType(c, WebUserControl1).QID = 5 Then
    If CType(c, WebUserControl1).RadioButtonList.SelectedIndex = 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(ByVal sender As System.Object, ByVal e As
    System.EventArgs) Handles Button1.Click
    Me.Validate()

    If Me.IsValid Then
    Response.Redirect("about:blank")
    End If
    End Sub
    End Class

    2) WebUserControl1.ascx.vb:

    Public MustInherit Class WebUserControl1
    Inherits System.Web.UI.UserControl
    Protected WithEvents Panel1 As System.Web.UI.WebControls.Panel
    Protected WithEvents Label1 As System.Web.UI.WebControls.Label
    Protected WithEvents RequiredFieldValidator1 As
    System.Web.UI.WebControls.RequiredFieldValidator
    Protected WithEvents RadioButtonList1 As
    System.Web.UI.WebControls.RadioButtonList

    #Region " Web Form Designer Generated Code "

    'This call is required by the Web Form Designer.
    <System.Diagnostics.DebuggerStepThrough()> Private Sub
    InitializeComponent()

    End Sub

    Private Sub Page_Init(ByVal sender As System.Object, ByVal e As
    System.EventArgs) Handles MyBase.Init
    'CODEGEN: This method call is required by the Web Form Designer
    'Do not modify it using the code editor.
    InitializeComponent()

    Me.RadioButtonList1.AutoPostBack = True
    End Sub

    #End Region

    Private mintQID As Integer

    Public ReadOnly Property RadioButtonList() As RadioButtonList
    Get
    Return RadioButtonList1
    End Get
    End Property

    Public ReadOnly Property QID() As Integer
    Get
    Return mintQID
    End Get
    End Property

    Public Sub InitQuestion(ByVal QID As Integer)
    mintQID = QID
    Label1.Text = "Question " & mintQID.ToString()

    With RadioButtonList1.Items
    .Add("1")
    .Add("2")
    .Add("3")
    End With
    End Sub

    Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
    System.EventArgs) Handles MyBase.Load
    'Put user code to initialize the page here
    End Sub

    End Class
    SLE, Dec 10, 2003
    #3
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Paul Aspinall

    SmartNavigation

    Paul Aspinall, Jul 8, 2003, in forum: ASP .Net
    Replies:
    0
    Views:
    333
    Paul Aspinall
    Jul 8, 2003
  2. Paul Aspinall

    SmartNavigation.

    Paul Aspinall, Jul 8, 2003, in forum: ASP .Net
    Replies:
    1
    Views:
    474
    Steve C. Orr, MCSD
    Jul 8, 2003
  3. Nicolas LeBlanc

    SmartNavigation & application crashing..

    Nicolas LeBlanc, Jul 15, 2003, in forum: ASP .Net
    Replies:
    1
    Views:
    417
    Ravikanth[MVP]
    Jul 16, 2003
  4. catweezle2010
    Replies:
    0
    Views:
    384
    catweezle2010
    Jan 26, 2006
  5. Tracey
    Replies:
    0
    Views:
    123
    Tracey
    Apr 26, 2006
Loading...

Share This Page