RadioButtonList, Web User Control, Firefox, IE

Discussion in 'ASP .Net' started by Paul, Jun 19, 2008.

  1. Paul

    Paul Guest

    Hallo,

    I have a radiobuttonlist control that is added on a custom Web User Control.
    This control has a property that exposes the SelectedIndex property of the
    embedded radiobuttonlist.

    When running this in IE, behaviour is as I would expect it. If I select an
    item and do a postback, the page remembers my selection when reloading, and
    the SelectedIndex property of my control returns the correct value.

    When running this in Firefox 3, I always get a -1 for the SelectedIndex
    prop, and the page does not remember my selection when reloading.

    If I add a radiobuttonlist directly on to an ASPX page, behaviour is as
    expected. Only fails in Firefox when the control is on a custom Web User
    Control.

    Below I will paste the aspx, ascx, and their respective code behind files.
    ..Net Framework 3.5. Any advice would be appreciated.

    Thanks
    Paul

    1. FF.aspx

    <%@ Page Language="VB" AutoEventWireup="false" CodeFile="FF.aspx.vb"
    Inherits="FF" %>

    <%@ Register Src="TEST.ascx" TagName="TESTcontrol" TagPrefix="uc1" %>

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

    <html xmlns="http://www.w3.org/1999/xhtml">
    <head runat="server">
    <title>Untitled Page</title>
    </head>
    <body>
    <form id="form1" runat="server">
    <div>

    <asp:placeHolder ID="PlaceHolder1" runat="server"></asp:placeHolder>

    </div>
    <asp:Button ID="Button1" runat="server" Text="Button" Width="55px" />
    </form>
    </body>
    </html>

    2. FF.aspx.vb

    Partial Class FF
    Inherits System.Web.UI.Page
    Protected WithEvents rbl As test
    Protected Sub Page_Load(ByVal sender As Object, ByVal e As
    System.EventArgs) Handles Me.Load
    rbl = CType(Me.LoadControl("TEST.ascx"), TEST)
    rbl.ID = "rblID99"
    PlaceHolder1.Controls.Add(rbl)
    End Sub
    Protected Sub Button1_Click(ByVal sender As Object, ByVal e As
    System.EventArgs) Handles Button1.Click
    Check(Me)
    End Sub
    Sub Check(ByVal _control As Control)
    If _control.ID IsNot Nothing Then
    If _control.GetType.ToString =
    "System.Web.UI.WebControls.RadioButtonList" Then
    Response.Write(CType(_control,
    RadioButtonList).SelectedIndex & " - selected index<br/>")
    If CType(_control, RadioButtonList).SelectedIndex < 0 Then
    MsgBox("Not checked.", MsgBoxStyle.ApplicationModal,
    "Questions.")
    End If
    End If
    End If
    If _control.HasControls Then
    For Each ctrl As Control In _control.Controls
    Check(ctrl)
    Next
    End If
    End Sub
    End Class

    3. TEST.ascx

    <%@ Control Language="VB" AutoEventWireup="false" CodeFile="TEST.ascx.vb"
    Inherits="TEST" Classname="TEST"%>

    <p style="width: 500px">

    <asp:Label ID="Question_TXT" runat="server">Q</asp:Label>
    </p>
    <p style="width: 500px">
    <asp:RadioButtonList ID="Answer_RBL" runat="server">
    <asp:ListItem></asp:ListItem>
    <asp:ListItem></asp:ListItem>
    </asp:RadioButtonList>
    </p>
    </p>

    4. TEST.ascx.vb

    Partial Class TEST
    Inherits System.Web.UI.UserControl
    Public ReadOnly Property SelectedIndex() As Integer
    Get
    Return Answer_RBL.SelectedIndex
    End Get
    End Property

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As
    System.EventArgs) Handles Me.Load
    Question_TXT.Text = "Pick One"
    Answer_RBL.Items(0).Text = vbTab & "First"
    Answer_RBL.Items(1).Text = vbTab & "Second"
    End Sub
    End Class
     
    Paul, Jun 19, 2008
    #1
    1. Advertising

  2. Paul

    bruce barker Guest

    its a bug in IE, it should send -1 also.

    you are loading the user control too late in the page lifecycle, so that it
    does not exist when postback data is applied. the proper place to load
    dynamic controls is in the CreateChildControls method (which was designed for
    this, or OnInit in a pinch)

    -- bruce (sqlwork.com)


    "Paul" wrote:

    > Hallo,
    >
    > I have a radiobuttonlist control that is added on a custom Web User Control.
    > This control has a property that exposes the SelectedIndex property of the
    > embedded radiobuttonlist.
    >
    > When running this in IE, behaviour is as I would expect it. If I select an
    > item and do a postback, the page remembers my selection when reloading, and
    > the SelectedIndex property of my control returns the correct value.
    >
    > When running this in Firefox 3, I always get a -1 for the SelectedIndex
    > prop, and the page does not remember my selection when reloading.
    >
    > If I add a radiobuttonlist directly on to an ASPX page, behaviour is as
    > expected. Only fails in Firefox when the control is on a custom Web User
    > Control.
    >
    > Below I will paste the aspx, ascx, and their respective code behind files.
    > .Net Framework 3.5. Any advice would be appreciated.
    >
    > Thanks
    > Paul
    >
    > 1. FF.aspx
    >
    > <%@ Page Language="VB" AutoEventWireup="false" CodeFile="FF.aspx.vb"
    > Inherits="FF" %>
    >
    > <%@ Register Src="TEST.ascx" TagName="TESTcontrol" TagPrefix="uc1" %>
    >
    > <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
    > "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    >
    > <html xmlns="http://www.w3.org/1999/xhtml">
    > <head runat="server">
    > <title>Untitled Page</title>
    > </head>
    > <body>
    > <form id="form1" runat="server">
    > <div>
    >
    > <asp:placeHolder ID="PlaceHolder1" runat="server"></asp:placeHolder>
    >
    > </div>
    > <asp:Button ID="Button1" runat="server" Text="Button" Width="55px" />
    > </form>
    > </body>
    > </html>
    >
    > 2. FF.aspx.vb
    >
    > Partial Class FF
    > Inherits System.Web.UI.Page
    > Protected WithEvents rbl As test
    > Protected Sub Page_Load(ByVal sender As Object, ByVal e As
    > System.EventArgs) Handles Me.Load
    > rbl = CType(Me.LoadControl("TEST.ascx"), TEST)
    > rbl.ID = "rblID99"
    > PlaceHolder1.Controls.Add(rbl)
    > End Sub
    > Protected Sub Button1_Click(ByVal sender As Object, ByVal e As
    > System.EventArgs) Handles Button1.Click
    > Check(Me)
    > End Sub
    > Sub Check(ByVal _control As Control)
    > If _control.ID IsNot Nothing Then
    > If _control.GetType.ToString =
    > "System.Web.UI.WebControls.RadioButtonList" Then
    > Response.Write(CType(_control,
    > RadioButtonList).SelectedIndex & " - selected index<br/>")
    > If CType(_control, RadioButtonList).SelectedIndex < 0 Then
    > MsgBox("Not checked.", MsgBoxStyle.ApplicationModal,
    > "Questions.")
    > End If
    > End If
    > End If
    > If _control.HasControls Then
    > For Each ctrl As Control In _control.Controls
    > Check(ctrl)
    > Next
    > End If
    > End Sub
    > End Class
    >
    > 3. TEST.ascx
    >
    > <%@ Control Language="VB" AutoEventWireup="false" CodeFile="TEST.ascx.vb"
    > Inherits="TEST" Classname="TEST"%>
    >
    > <p style="width: 500px">
    >
    > <asp:Label ID="Question_TXT" runat="server">Q</asp:Label>
    > </p>
    > <p style="width: 500px">
    > <asp:RadioButtonList ID="Answer_RBL" runat="server">
    > <asp:ListItem></asp:ListItem>
    > <asp:ListItem></asp:ListItem>
    > </asp:RadioButtonList>
    > </p>
    > </p>
    >
    > 4. TEST.ascx.vb
    >
    > Partial Class TEST
    > Inherits System.Web.UI.UserControl
    > Public ReadOnly Property SelectedIndex() As Integer
    > Get
    > Return Answer_RBL.SelectedIndex
    > End Get
    > End Property
    >
    > Protected Sub Page_Load(ByVal sender As Object, ByVal e As
    > System.EventArgs) Handles Me.Load
    > Question_TXT.Text = "Pick One"
    > Answer_RBL.Items(0).Text = vbTab & "First"
    > Answer_RBL.Items(1).Text = vbTab & "Second"
    > End Sub
    > End Class
    >
     
    bruce barker, Jun 19, 2008
    #2
    1. Advertising

  3. Paul

    Teemu Keiski Guest

    Hi,

    moving the code to create the control to OnInit or CreateChildControls
    doesn't change the thing, ASP.NET is able to load postback data for controls
    loaded in Page_Load (postback data loading happens in two steps once before
    and once after Load - you can cofirm that by checking page trace).

    By the way, for testing purposes maybe OK, but don't use MSgBox in ASp.NET
    in production as it shows the MSgBoxes only on the server machine...

    The issue itself relates that you add vbTab to the ListItem's Text in code:

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As
    System.EventArgs) Handles Me.Load
    Question_TXT.Text = "Pick One"
    Answer_RBL.Items(0).Text = vbTab & "First"
    Answer_RBL.Items(1).Text = vbTab & "Second"
    End Sub

    Remove the vbTab appendings and you'll note the thing starts to work just
    fine (with control loaded in Page_Load, although in practise doing it in
    Init or CreateChildControls eases certain things in the long run.

    So I suppose it relates to other browser dealing with the tab...

    --
    Teemu Keiski
    AspInsider, ASP.NET MVP
    http://blogs.aspadvice.com/joteke
    http://teemukeiski.net





    "Paul" <> wrote in message
    news:...
    > Hallo,
    >
    > I have a radiobuttonlist control that is added on a custom Web User
    > Control.
    > This control has a property that exposes the SelectedIndex property of the
    > embedded radiobuttonlist.
    >
    > When running this in IE, behaviour is as I would expect it. If I select an
    > item and do a postback, the page remembers my selection when reloading,
    > and
    > the SelectedIndex property of my control returns the correct value.
    >
    > When running this in Firefox 3, I always get a -1 for the SelectedIndex
    > prop, and the page does not remember my selection when reloading.
    >
    > If I add a radiobuttonlist directly on to an ASPX page, behaviour is as
    > expected. Only fails in Firefox when the control is on a custom Web User
    > Control.
    >
    > Below I will paste the aspx, ascx, and their respective code behind files.
    > .Net Framework 3.5. Any advice would be appreciated.
    >
    > Thanks
    > Paul
    >
    > 1. FF.aspx
    >
    > <%@ Page Language="VB" AutoEventWireup="false" CodeFile="FF.aspx.vb"
    > Inherits="FF" %>
    >
    > <%@ Register Src="TEST.ascx" TagName="TESTcontrol" TagPrefix="uc1" %>
    >
    > <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
    > "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    >
    > <html xmlns="http://www.w3.org/1999/xhtml">
    > <head runat="server">
    > <title>Untitled Page</title>
    > </head>
    > <body>
    > <form id="form1" runat="server">
    > <div>
    >
    > <asp:placeHolder ID="PlaceHolder1"
    > runat="server"></asp:placeHolder>
    >
    > </div>
    > <asp:Button ID="Button1" runat="server" Text="Button" Width="55px" />
    > </form>
    > </body>
    > </html>
    >
    > 2. FF.aspx.vb
    >
    > Partial Class FF
    > Inherits System.Web.UI.Page
    > Protected WithEvents rbl As test
    > Protected Sub Page_Load(ByVal sender As Object, ByVal e As
    > System.EventArgs) Handles Me.Load
    > rbl = CType(Me.LoadControl("TEST.ascx"), TEST)
    > rbl.ID = "rblID99"
    > PlaceHolder1.Controls.Add(rbl)
    > End Sub
    > Protected Sub Button1_Click(ByVal sender As Object, ByVal e As
    > System.EventArgs) Handles Button1.Click
    > Check(Me)
    > End Sub
    > Sub Check(ByVal _control As Control)
    > If _control.ID IsNot Nothing Then
    > If _control.GetType.ToString =
    > "System.Web.UI.WebControls.RadioButtonList" Then
    > Response.Write(CType(_control,
    > RadioButtonList).SelectedIndex & " - selected index<br/>")
    > If CType(_control, RadioButtonList).SelectedIndex < 0 Then
    > MsgBox("Not checked.", MsgBoxStyle.ApplicationModal,
    > "Questions.")
    > End If
    > End If
    > End If
    > If _control.HasControls Then
    > For Each ctrl As Control In _control.Controls
    > Check(ctrl)
    > Next
    > End If
    > End Sub
    > End Class
    >
    > 3. TEST.ascx
    >
    > <%@ Control Language="VB" AutoEventWireup="false" CodeFile="TEST.ascx.vb"
    > Inherits="TEST" Classname="TEST"%>
    >
    > <p style="width: 500px">
    >
    > <asp:Label ID="Question_TXT" runat="server">Q</asp:Label>
    > </p>
    > <p style="width: 500px">
    > <asp:RadioButtonList ID="Answer_RBL" runat="server">
    > <asp:ListItem></asp:ListItem>
    > <asp:ListItem></asp:ListItem>
    > </asp:RadioButtonList>
    > </p>
    > </p>
    >
    > 4. TEST.ascx.vb
    >
    > Partial Class TEST
    > Inherits System.Web.UI.UserControl
    > Public ReadOnly Property SelectedIndex() As Integer
    > Get
    > Return Answer_RBL.SelectedIndex
    > End Get
    > End Property
    >
    > Protected Sub Page_Load(ByVal sender As Object, ByVal e As
    > System.EventArgs) Handles Me.Load
    > Question_TXT.Text = "Pick One"
    > Answer_RBL.Items(0).Text = vbTab & "First"
    > Answer_RBL.Items(1).Text = vbTab & "Second"
    > End Sub
    > End Class
    >
     
    Teemu Keiski, Jun 19, 2008
    #3
  4. Paul

    Teemu Keiski Guest

    To add, the issue still occurred in my test case even when creating the
    control in CreateChildControls, when ListItem had vbTabs.

    Teemu


    "Teemu Keiski" <> wrote in message
    news:%...
    > Hi,
    >
    > moving the code to create the control to OnInit or CreateChildControls
    > doesn't change the thing, ASP.NET is able to load postback data for
    > controls loaded in Page_Load (postback data loading happens in two steps
    > once before and once after Load - you can cofirm that by checking page
    > trace).
    >
    > By the way, for testing purposes maybe OK, but don't use MSgBox in ASp.NET
    > in production as it shows the MSgBoxes only on the server machine...
    >
    > The issue itself relates that you add vbTab to the ListItem's Text in
    > code:
    >
    > Protected Sub Page_Load(ByVal sender As Object, ByVal e As
    > System.EventArgs) Handles Me.Load
    > Question_TXT.Text = "Pick One"
    > Answer_RBL.Items(0).Text = vbTab & "First"
    > Answer_RBL.Items(1).Text = vbTab & "Second"
    > End Sub
    >
    > Remove the vbTab appendings and you'll note the thing starts to work just
    > fine (with control loaded in Page_Load, although in practise doing it in
    > Init or CreateChildControls eases certain things in the long run.
    >
    > So I suppose it relates to other browser dealing with the tab...
    >
    > --
    > Teemu Keiski
    > AspInsider, ASP.NET MVP
    > http://blogs.aspadvice.com/joteke
    > http://teemukeiski.net
    >
    >
    >
    >
    >
    > "Paul" <> wrote in message
    > news:...
    >> Hallo,
    >>
    >> I have a radiobuttonlist control that is added on a custom Web User
    >> Control.
    >> This control has a property that exposes the SelectedIndex property of
    >> the
    >> embedded radiobuttonlist.
    >>
    >> When running this in IE, behaviour is as I would expect it. If I select
    >> an
    >> item and do a postback, the page remembers my selection when reloading,
    >> and
    >> the SelectedIndex property of my control returns the correct value.
    >>
    >> When running this in Firefox 3, I always get a -1 for the SelectedIndex
    >> prop, and the page does not remember my selection when reloading.
    >>
    >> If I add a radiobuttonlist directly on to an ASPX page, behaviour is as
    >> expected. Only fails in Firefox when the control is on a custom Web User
    >> Control.
    >>
    >> Below I will paste the aspx, ascx, and their respective code behind
    >> files.
    >> .Net Framework 3.5. Any advice would be appreciated.
    >>
    >> Thanks
    >> Paul
    >>
    >> 1. FF.aspx
    >>
    >> <%@ Page Language="VB" AutoEventWireup="false" CodeFile="FF.aspx.vb"
    >> Inherits="FF" %>
    >>
    >> <%@ Register Src="TEST.ascx" TagName="TESTcontrol" TagPrefix="uc1" %>
    >>
    >> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
    >> "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    >>
    >> <html xmlns="http://www.w3.org/1999/xhtml">
    >> <head runat="server">
    >> <title>Untitled Page</title>
    >> </head>
    >> <body>
    >> <form id="form1" runat="server">
    >> <div>
    >>
    >> <asp:placeHolder ID="PlaceHolder1"
    >> runat="server"></asp:placeHolder>
    >>
    >> </div>
    >> <asp:Button ID="Button1" runat="server" Text="Button" Width="55px" />
    >> </form>
    >> </body>
    >> </html>
    >>
    >> 2. FF.aspx.vb
    >>
    >> Partial Class FF
    >> Inherits System.Web.UI.Page
    >> Protected WithEvents rbl As test
    >> Protected Sub Page_Load(ByVal sender As Object, ByVal e As
    >> System.EventArgs) Handles Me.Load
    >> rbl = CType(Me.LoadControl("TEST.ascx"), TEST)
    >> rbl.ID = "rblID99"
    >> PlaceHolder1.Controls.Add(rbl)
    >> End Sub
    >> Protected Sub Button1_Click(ByVal sender As Object, ByVal e As
    >> System.EventArgs) Handles Button1.Click
    >> Check(Me)
    >> End Sub
    >> Sub Check(ByVal _control As Control)
    >> If _control.ID IsNot Nothing Then
    >> If _control.GetType.ToString =
    >> "System.Web.UI.WebControls.RadioButtonList" Then
    >> Response.Write(CType(_control,
    >> RadioButtonList).SelectedIndex & " - selected index<br/>")
    >> If CType(_control, RadioButtonList).SelectedIndex < 0 Then
    >> MsgBox("Not checked.", MsgBoxStyle.ApplicationModal,
    >> "Questions.")
    >> End If
    >> End If
    >> End If
    >> If _control.HasControls Then
    >> For Each ctrl As Control In _control.Controls
    >> Check(ctrl)
    >> Next
    >> End If
    >> End Sub
    >> End Class
    >>
    >> 3. TEST.ascx
    >>
    >> <%@ Control Language="VB" AutoEventWireup="false" CodeFile="TEST.ascx.vb"
    >> Inherits="TEST" Classname="TEST"%>
    >>
    >> <p style="width: 500px">
    >>
    >> <asp:Label ID="Question_TXT" runat="server">Q</asp:Label>
    >> </p>
    >> <p style="width: 500px">
    >> <asp:RadioButtonList ID="Answer_RBL" runat="server">
    >> <asp:ListItem></asp:ListItem>
    >> <asp:ListItem></asp:ListItem>
    >> </asp:RadioButtonList>
    >> </p>
    >> </p>
    >>
    >> 4. TEST.ascx.vb
    >>
    >> Partial Class TEST
    >> Inherits System.Web.UI.UserControl
    >> Public ReadOnly Property SelectedIndex() As Integer
    >> Get
    >> Return Answer_RBL.SelectedIndex
    >> End Get
    >> End Property
    >>
    >> Protected Sub Page_Load(ByVal sender As Object, ByVal e As
    >> System.EventArgs) Handles Me.Load
    >> Question_TXT.Text = "Pick One"
    >> Answer_RBL.Items(0).Text = vbTab & "First"
    >> Answer_RBL.Items(1).Text = vbTab & "Second"
    >> End Sub
    >> End Class
    >>

    >
    >
     
    Teemu Keiski, Jun 19, 2008
    #4
  5. Thanks for your Teemu's informative inputs.

    Seems the problem is related to the firefox 3's handling on <select>
    options which contains tab chars. BTW, I agree that "OnInit" and
    "CreateChildControls" are the prefered place for dynamic controls though it
    may not address the problem here.

    Sincerely,

    Steven Cheng

    Microsoft MSDN Online Support Lead


    Delighting our customers is our #1 priority. We welcome your comments and
    suggestions about how we can improve the support we provide to you. Please
    feel free to let my manager know what you think of the level of service
    provided. You can send feedback directly to my manager at:
    .

    ==================================================
    Get notification to my posts through email? Please refer to
    http://msdn.microsoft.com/subscriptions/managednewsgroups/default.aspx#notif
    ications.

    ==================================================
    This posting is provided "AS IS" with no warranties, and confers no rights.
    --------------------
    >From: "Teemu Keiski" <>
    >References: <>

    <#>
    >Subject: Re: RadioButtonList, Web User Control, Firefox, IE
    >Date: Thu, 19 Jun 2008 21:48:46 +0300


    >
    >To add, the issue still occurred in my test case even when creating the
    >control in CreateChildControls, when ListItem had vbTabs.
    >
    >Teemu
    >
    >
    >"Teemu Keiski" <> wrote in message
    >news:%...
    >> Hi,
    >>
    >> moving the code to create the control to OnInit or CreateChildControls
    >> doesn't change the thing, ASP.NET is able to load postback data for
    >> controls loaded in Page_Load (postback data loading happens in two steps
    >> once before and once after Load - you can cofirm that by checking page
    >> trace).
    >>
    >> By the way, for testing purposes maybe OK, but don't use MSgBox in

    ASp.NET
    >> in production as it shows the MSgBoxes only on the server machine...
    >>
    >> The issue itself relates that you add vbTab to the ListItem's Text in
    >> code:
    >>
    >> Protected Sub Page_Load(ByVal sender As Object, ByVal e As
    >> System.EventArgs) Handles Me.Load
    >> Question_TXT.Text = "Pick One"
    >> Answer_RBL.Items(0).Text = vbTab & "First"
    >> Answer_RBL.Items(1).Text = vbTab & "Second"
    >> End Sub
    >>
    >> Remove the vbTab appendings and you'll note the thing starts to work

    just
    >> fine (with control loaded in Page_Load, although in practise doing it in
    >> Init or CreateChildControls eases certain things in the long run.
    >>
    >> So I suppose it relates to other browser dealing with the tab...
    >>
    >> --
    >> Teemu Keiski
    >> AspInsider, ASP.NET MVP
    >> http://blogs.aspadvice.com/joteke
    >> http://teemukeiski.net
    >>
    >>
    >>
    >>
    >>
    >> "Paul" <> wrote in message
    >> news:...
    >>> Hallo,
    >>>
    >>> I have a radiobuttonlist control that is added on a custom Web User
    >>> Control.
    >>> This control has a property that exposes the SelectedIndex property of
    >>> the
    >>> embedded radiobuttonlist.
    >>>
    >>> When running this in IE, behaviour is as I would expect it. If I select
    >>> an
    >>> item and do a postback, the page remembers my selection when reloading,
    >>> and
    >>> the SelectedIndex property of my control returns the correct value.
    >>>
    >>> When running this in Firefox 3, I always get a -1 for the SelectedIndex
    >>> prop, and the page does not remember my selection when reloading.
    >>>
    >>> If I add a radiobuttonlist directly on to an ASPX page, behaviour is as
    >>> expected. Only fails in Firefox when the control is on a custom Web User
    >>> Control.
    >>>
    >>> Below I will paste the aspx, ascx, and their respective code behind
    >>> files.
    >>> .Net Framework 3.5. Any advice would be appreciated.
    >>>
    >>> Thanks
    >>> Paul
    >>>
    >>> 1. FF.aspx
    >>>
    >>> <%@ Page Language="VB" AutoEventWireup="false" CodeFile="FF.aspx.vb"
    >>> Inherits="FF" %>
    >>>
    >>> <%@ Register Src="TEST.ascx" TagName="TESTcontrol" TagPrefix="uc1" %>
    >>>
    >>> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
    >>> "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    >>>
    >>> <html xmlns="http://www.w3.org/1999/xhtml">
    >>> <head runat="server">
    >>> <title>Untitled Page</title>
    >>> </head>
    >>> <body>
    >>> <form id="form1" runat="server">
    >>> <div>
    >>>
    >>> <asp:placeHolder ID="PlaceHolder1"
    >>> runat="server"></asp:placeHolder>
    >>>
    >>> </div>
    >>> <asp:Button ID="Button1" runat="server" Text="Button" Width="55px" />
    >>> </form>
    >>> </body>
    >>> </html>
    >>>
    >>> 2. FF.aspx.vb
    >>>
    >>> Partial Class FF
    >>> Inherits System.Web.UI.Page
    >>> Protected WithEvents rbl As test
    >>> Protected Sub Page_Load(ByVal sender As Object, ByVal e As
    >>> System.EventArgs) Handles Me.Load
    >>> rbl = CType(Me.LoadControl("TEST.ascx"), TEST)
    >>> rbl.ID = "rblID99"
    >>> PlaceHolder1.Controls.Add(rbl)
    >>> End Sub
    >>> Protected Sub Button1_Click(ByVal sender As Object, ByVal e As
    >>> System.EventArgs) Handles Button1.Click
    >>> Check(Me)
    >>> End Sub
    >>> Sub Check(ByVal _control As Control)
    >>> If _control.ID IsNot Nothing Then
    >>> If _control.GetType.ToString =
    >>> "System.Web.UI.WebControls.RadioButtonList" Then
    >>> Response.Write(CType(_control,
    >>> RadioButtonList).SelectedIndex & " - selected index<br/>")
    >>> If CType(_control, RadioButtonList).SelectedIndex < 0

    Then
    >>> MsgBox("Not checked.", MsgBoxStyle.ApplicationModal,
    >>> "Questions.")
    >>> End If
    >>> End If
    >>> End If
    >>> If _control.HasControls Then
    >>> For Each ctrl As Control In _control.Controls
    >>> Check(ctrl)
    >>> Next
    >>> End If
    >>> End Sub
    >>> End Class
    >>>
    >>> 3. TEST.ascx
    >>>
    >>> <%@ Control Language="VB" AutoEventWireup="false"

    CodeFile="TEST.ascx.vb"
    >>> Inherits="TEST" Classname="TEST"%>
    >>>
    >>> <p style="width: 500px">
    >>>
    >>> <asp:Label ID="Question_TXT" runat="server">Q</asp:Label>
    >>> </p>
    >>> <p style="width: 500px">
    >>> <asp:RadioButtonList ID="Answer_RBL" runat="server">
    >>> <asp:ListItem></asp:ListItem>
    >>> <asp:ListItem></asp:ListItem>
    >>> </asp:RadioButtonList>
    >>> </p>
    >>> </p>
    >>>
    >>> 4. TEST.ascx.vb
    >>>
    >>> Partial Class TEST
    >>> Inherits System.Web.UI.UserControl
    >>> Public ReadOnly Property SelectedIndex() As Integer
    >>> Get
    >>> Return Answer_RBL.SelectedIndex
    >>> End Get
    >>> End Property
    >>>
    >>> Protected Sub Page_Load(ByVal sender As Object, ByVal e As
    >>> System.EventArgs) Handles Me.Load
    >>> Question_TXT.Text = "Pick One"
    >>> Answer_RBL.Items(0).Text = vbTab & "First"
    >>> Answer_RBL.Items(1).Text = vbTab & "Second"
    >>> End Sub
    >>> End Class
    >>>

    >>
    >>

    >
    >
    >
     
    Steven Cheng [MSFT], Jun 20, 2008
    #5
  6. Paul

    Paul Guest

    Hi Teemu,

    Fantastic. So simple, and I spent so much time trying to track this down.
    Your help is appreciated. Thanks as well Bruce and Steven.

    By the way, in the sample I load the controls in the Page Load event, but in
    my actual page I load it in PreInit.

    Thanks again
    Paul

    "Teemu Keiski" wrote:

    > Hi,
    >
    > moving the code to create the control to OnInit or CreateChildControls
    > doesn't change the thing, ASP.NET is able to load postback data for controls
    > loaded in Page_Load (postback data loading happens in two steps once before
    > and once after Load - you can cofirm that by checking page trace).
    >
    > By the way, for testing purposes maybe OK, but don't use MSgBox in ASp.NET
    > in production as it shows the MSgBoxes only on the server machine...
    >
    > The issue itself relates that you add vbTab to the ListItem's Text in code:
    >
    > Protected Sub Page_Load(ByVal sender As Object, ByVal e As
    > System.EventArgs) Handles Me.Load
    > Question_TXT.Text = "Pick One"
    > Answer_RBL.Items(0).Text = vbTab & "First"
    > Answer_RBL.Items(1).Text = vbTab & "Second"
    > End Sub
    >
    > Remove the vbTab appendings and you'll note the thing starts to work just
    > fine (with control loaded in Page_Load, although in practise doing it in
    > Init or CreateChildControls eases certain things in the long run.
    >
    > So I suppose it relates to other browser dealing with the tab...
    >
    > --
    > Teemu Keiski
    > AspInsider, ASP.NET MVP
    > http://blogs.aspadvice.com/joteke
    > http://teemukeiski.net
    >
    >
    >
    >
    >
    > "Paul" <> wrote in message
    > news:...
    > > Hallo,
    > >
    > > I have a radiobuttonlist control that is added on a custom Web User
    > > Control.
    > > This control has a property that exposes the SelectedIndex property of the
    > > embedded radiobuttonlist.
    > >
    > > When running this in IE, behaviour is as I would expect it. If I select an
    > > item and do a postback, the page remembers my selection when reloading,
    > > and
    > > the SelectedIndex property of my control returns the correct value.
    > >
    > > When running this in Firefox 3, I always get a -1 for the SelectedIndex
    > > prop, and the page does not remember my selection when reloading.
    > >
    > > If I add a radiobuttonlist directly on to an ASPX page, behaviour is as
    > > expected. Only fails in Firefox when the control is on a custom Web User
    > > Control.
    > >
    > > Below I will paste the aspx, ascx, and their respective code behind files.
    > > .Net Framework 3.5. Any advice would be appreciated.
    > >
    > > Thanks
    > > Paul
    > >
    > > 1. FF.aspx
    > >
    > > <%@ Page Language="VB" AutoEventWireup="false" CodeFile="FF.aspx.vb"
    > > Inherits="FF" %>
    > >
    > > <%@ Register Src="TEST.ascx" TagName="TESTcontrol" TagPrefix="uc1" %>
    > >
    > > <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
    > > "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    > >
    > > <html xmlns="http://www.w3.org/1999/xhtml">
    > > <head runat="server">
    > > <title>Untitled Page</title>
    > > </head>
    > > <body>
    > > <form id="form1" runat="server">
    > > <div>
    > >
    > > <asp:placeHolder ID="PlaceHolder1"
    > > runat="server"></asp:placeHolder>
    > >
    > > </div>
    > > <asp:Button ID="Button1" runat="server" Text="Button" Width="55px" />
    > > </form>
    > > </body>
    > > </html>
    > >
    > > 2. FF.aspx.vb
    > >
    > > Partial Class FF
    > > Inherits System.Web.UI.Page
    > > Protected WithEvents rbl As test
    > > Protected Sub Page_Load(ByVal sender As Object, ByVal e As
    > > System.EventArgs) Handles Me.Load
    > > rbl = CType(Me.LoadControl("TEST.ascx"), TEST)
    > > rbl.ID = "rblID99"
    > > PlaceHolder1.Controls.Add(rbl)
    > > End Sub
    > > Protected Sub Button1_Click(ByVal sender As Object, ByVal e As
    > > System.EventArgs) Handles Button1.Click
    > > Check(Me)
    > > End Sub
    > > Sub Check(ByVal _control As Control)
    > > If _control.ID IsNot Nothing Then
    > > If _control.GetType.ToString =
    > > "System.Web.UI.WebControls.RadioButtonList" Then
    > > Response.Write(CType(_control,
    > > RadioButtonList).SelectedIndex & " - selected index<br/>")
    > > If CType(_control, RadioButtonList).SelectedIndex < 0 Then
    > > MsgBox("Not checked.", MsgBoxStyle.ApplicationModal,
    > > "Questions.")
    > > End If
    > > End If
    > > End If
    > > If _control.HasControls Then
    > > For Each ctrl As Control In _control.Controls
    > > Check(ctrl)
    > > Next
    > > End If
    > > End Sub
    > > End Class
    > >
    > > 3. TEST.ascx
    > >
    > > <%@ Control Language="VB" AutoEventWireup="false" CodeFile="TEST.ascx.vb"
    > > Inherits="TEST" Classname="TEST"%>
    > >
    > > <p style="width: 500px">
    > >
    > > <asp:Label ID="Question_TXT" runat="server">Q</asp:Label>
    > > </p>
    > > <p style="width: 500px">
    > > <asp:RadioButtonList ID="Answer_RBL" runat="server">
    > > <asp:ListItem></asp:ListItem>
    > > <asp:ListItem></asp:ListItem>
    > > </asp:RadioButtonList>
    > > </p>
    > > </p>
    > >
    > > 4. TEST.ascx.vb
    > >
    > > Partial Class TEST
    > > Inherits System.Web.UI.UserControl
    > > Public ReadOnly Property SelectedIndex() As Integer
    > > Get
    > > Return Answer_RBL.SelectedIndex
    > > End Get
    > > End Property
    > >
    > > Protected Sub Page_Load(ByVal sender As Object, ByVal e As
    > > System.EventArgs) Handles Me.Load
    > > Question_TXT.Text = "Pick One"
    > > Answer_RBL.Items(0).Text = vbTab & "First"
    > > Answer_RBL.Items(1).Text = vbTab & "Second"
    > > End Sub
    > > End Class
    > >

    >
    >
    >
     
    Paul, Jun 20, 2008
    #6
    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. ABC
    Replies:
    1
    Views:
    2,650
    Larry
    Oct 4, 2005
  2. ABC
    Replies:
    0
    Views:
    487
  3. Silvia Elena

    User control combining TextBox and RadioButtonList

    Silvia Elena, Feb 23, 2007, in forum: ASP .Net Building Controls
    Replies:
    0
    Views:
    323
    Silvia Elena
    Feb 23, 2007
  4. ABC
    Replies:
    0
    Views:
    206
  5. Martin Frank
    Replies:
    3
    Views:
    715
    Martin Frank
    Nov 1, 2006
Loading...

Share This Page