Results 1 to 12 of 12

Thread: Radiobuttonlist reverts from selected item

Hybrid View

  1. #1
    Hyperactive Member
    Join Date
    Mar 02
    Location
    Stockholm, Sweden
    Posts
    291

    Radiobuttonlist reverts from selected item

    Hi,

    I´m guessing this has been asked before. In fact I asked it myself some time ago about a dropdownlist.

    However the same solution doesn't seen to work, and I can't find the solution in the forum.

    I´m populating a radiobuttonlist in code on page load, allthough not when postback is true (I´ve checked this by the way).

    Autopostback is set to true, viewstate is enabled (everywhere I can think of, allthough only in the content page, if that matters)

    When I select an item, the postback happens, the populating does not happen, and the selection reverts back to the first item, which was never selected. It really looks stupid.

    Nowadays I have the knowledge to do this in javascript, but I would prefer not to. It can´t be that it should work like this, can it? The control would be useless. I want the index that is selected.

    Thanks.

    Fuga.
    Visual Studio 2010 xpress, Visual Studio 2008 pro, SQL Server, SQL Server management studio 2008 r2, MSAccess

  2. #2
    King of sapila
    Join Date
    Oct 06
    Location
    Greece
    Posts
    3,508

    Re: Radiobuttonlist reverts from selected item

    The code.
    Slow as hell.

  3. #3
    Hyperactive Member
    Join Date
    Mar 02
    Location
    Stockholm, Sweden
    Posts
    291

    Re: Radiobuttonlist reverts from selected item

    Here you go, sapator. Thanks!

    In a sub, called from page load (including the msgbox check, which fires):
    Code:
            If Page.IsPostBack = True Then
                MsgBox("Postback")
            End If
            If Page.IsPostBack = False Then
                Me.RadioButtonList1.Items.Clear()
                Me.RadioButtonList1.Items.Add("Placera här")
            End If
    and then further down, inside a loop:
    Code:
                If Me.IsPostBack = False Then
                    Dim rbitem As New ListItem
                    rbitem.Enabled = False
                    rbitem.Text = Left(stRw.Item(3), 45) & "..."
                    Me.RadioButtonList1.Items.Add(rbitem)
                    Me.RadioButtonList1.Items.Add("Placera här")
                End If
    and the aspx:
    Code:
                    <asp:RadioButtonList ID="RadioButtonList1" runat="server" ForeColor="Black" Font-Size="0.9em" AutoPostBack="True" ViewStateMode="Enabled">
                    </asp:RadioButtonList>
    so the postback is true, and the populating doesn´t happen, but still the first item gets selected.

    Fuga.
    Visual Studio 2010 xpress, Visual Studio 2008 pro, SQL Server, SQL Server management studio 2008 r2, MSAccess

  4. #4
    Hyperactive Member
    Join Date
    Mar 02
    Location
    Stockholm, Sweden
    Posts
    291

    Re: Radiobuttonlist reverts from selected item

    And before you ask

    I´m using the list to allow the user to chose where to put an item he creates. When doing so, he is only allowed to place the item between already existing item, so as to create "in-between" levels. Hence the disabled items comes from existing data in db, and the enabled items are named "Placera här", which means "place here".

    Fuga.
    Visual Studio 2010 xpress, Visual Studio 2008 pro, SQL Server, SQL Server management studio 2008 r2, MSAccess

  5. #5
    King of sapila
    Join Date
    Oct 06
    Location
    Greece
    Posts
    3,508

    Re: Radiobuttonlist reverts from selected item

    I don't really understand what you want.
    This will work:
    Code:
      Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
            If Page.IsPostBack = True Then
    'never put a messagebox in asp.net!
                MsgBox("Postback")
            End If
            If Page.IsPostBack = False Then
                Me.RadioButtonList1.Items.Clear()
                Me.RadioButtonList1.Items.Add("Placera här")
            End If
    
            If Me.IsPostBack = False Then
                Dim rbitem As New ListItem
                rbitem.Enabled = False
                rbitem.Text = "something"
                Me.RadioButtonList1.Items.Add(rbitem)
                Me.RadioButtonList1.Items.Add("Placera här")
            End If
        End Sub
    What exactly is the problem?
    Slow as hell.

  6. #6
    Hyperactive Member
    Join Date
    Mar 02
    Location
    Stockholm, Sweden
    Posts
    291

    Re: Radiobuttonlist reverts from selected item

    What exactly is the problem?
    The problem is that the wrong item is selected after postback, which means that it looks bad, and also that I can´t use the value or index in code later on, because it´s always 0.

    'never put a messagebox in asp.net!
    Why Is there something I don´t know about this? In fact I´m beginning to think you should never put anything in asp.net

    Fuga.
    Visual Studio 2010 xpress, Visual Studio 2008 pro, SQL Server, SQL Server management studio 2008 r2, MSAccess

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •