RadioButtonList.SelectedIndexChanged as UpdatePanel Trigger

Last post 10-06-2007 7:06 AM by Garbin. 14 replies.

Sort Posts:

  • RadioButtonList.SelectedIndexChanged as UpdatePanel Trigger

    08-08-2006, 4:05 PM
    • Loading...
    • NinjaFish
    • Joined on 08-04-2006, 3:46 PM
    • Posts 4
    I have something similar to the following:

    <atlas:UpdatePanel ID="myUpdatePanel" Mode="Conditional" runat="server">
        <ContentTemplate>
           <asp:SomeControl ... />
        </ContentTemplate>
        <Triggers>
           <atlas:ControlEventTrigger ControlID="myRbl" EventName="SelectedIndexChanged" />
        </Triggers>
    </atlas:UpdatePanel>

    <asp:RadioButtonList ID="myRbl" AutoPostBack="true" OnSelectedIndexChanged="..." runat="server">
        <asp:ListItem ... />
        <asp:ListItem ... />
        <asp:ListItem ... />
    </asp:RadioButtonList>


    My problem is that the RBL causes the entire page to post back, rather than causing an AJAX postback. I have used this pattern of updating an UpdatePanel using a control outside of the UpdatePanel before. For example, if I were to use a Button instead of the RBL, it would work fine. The RBL has been the only control (so far) where this does not work for me.

    As a workaround, I can wrap the RBL in its own UpdatePanel and everything works fine. Still, I don't think that's how it's supposed to work.

    This is on the July CTP.
  • Re: RadioButtonList.SelectedIndexChanged as UpdatePanel Trigger

    08-08-2006, 4:40 PM
    • Loading...
    • byersjus
    • Joined on 10-27-2005, 8:34 PM
    • Posts 13
    I'm pretty sure that's how its supposed to work.

    Your RBL is outside of any updatepanel and has AutoPostBack="true" so thats what it does.

    Did you try setting AutoPostBack to false and leaving it outside of an updatepanel?

    If that doesn't work I guess you'll have to "work around" the intended actions with the second update panel.
  • Re: RadioButtonList.SelectedIndexChanged as UpdatePanel Trigger

    08-08-2006, 6:25 PM
    • Loading...
    • NinjaFish
    • Joined on 08-04-2006, 3:46 PM
    • Posts 4
    Here is a simple example that works in the way that I described. If you run this, you will notice that Atlas picks up the AutoPostBack from the TextBox control and updates the Label control accordingly via AJAX. However, the AutoPostBack from the RadioButtonList causes a full PostBack. The two behave in completely different manners, and based on my experience, I believe the TextBox is exhibiting the correct behavior.
     
    <%@ Page Language="C#" %>
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

    <script runat="server">

    void myTextBox_TextChanged( object sender, EventArgs e )
    {
    myLabel.Text = myTextBox.Text;
    }

    void myRadioButtonList_SelectedIndexChanged( object sender, EventArgs e )
    {
    myLabel.Text = myRadioButtonList.SelectedValue;
    }

    </script>

    <html xmlns="http://www.w3.org/1999/xhtml" >
    <head runat="server">
    <title>Untitled Page</title>
    </head>
    <body>
    <form id="form1" runat="server">
    <atlas:ScriptManager ID="scriptManager" EnablePartialRendering="true" runat="server" />

    <atlas:UpdatePanel ID="myUpdatePanel" Mode="Conditional" runat="server">
    <ContentTemplate>
    <asp:Label ID="myLabel" Text="Initial Text" runat="server" />
    </ContentTemplate>
    <Triggers>
    <atlas:ControlEventTrigger ControlID="myTextBox" EventName="TextChanged" />
    <atlas:ControlEventTrigger ControlID="myRadioButtonList" EventName="SelectedIndexChanged" />
    </Triggers>
    </atlas:UpdatePanel>

    <asp:TextBox ID="myTextBox" AutoPostBack="true" OnTextChanged="myTextBox_TextChanged" runat="server" />

    <asp:RadioButtonList ID="myRadioButtonList" AutoPostBack="true"
    OnSelectedIndexChanged="myRadioButtonList_SelectedIndexChanged" runat="server">
    <asp:ListItem Value="Radio Button 1" />
    <asp:ListItem Value="Radio Button 2" />
    <asp:ListItem Value="Radio Button 3" />
    </asp:RadioButtonList>
    </form>
    </body>
    </html>
     
  • Re: RadioButtonList.SelectedIndexChanged as UpdatePanel Trigger

    08-08-2006, 7:00 PM
    • Loading...
    • Garbin
    • Joined on 09-17-2004, 12:35 PM
    • Sassari, Italy
    • Posts 1,494
    • ASPInsiders
      TrustedFriends-MVPs
    Hi,

    there's an issue with list controls like RadioButtonList or CheckBoxList used as trigger for an UpdatePanel. The full postback happens because the trigger registers the list container as an asynchronous control but the postback is fired by a child control with a different id. I've added this issue to the unofficial bug/issue list.
    Alessandro Gallo | Blog | My book: ASP.NET AJAX In Action
  • Re: RadioButtonList.SelectedIndexChanged as UpdatePanel Trigger

    08-15-2006, 12:57 AM
    • Loading...
    • DamonC
    • Joined on 08-15-2006, 4:48 AM
    • Posts 2

    I had exactly the same problem - I've come up with a workaround which seems to work for me so I thought I'd share in case anybody else would like to implement it (I'm only targetting Internet Explorer as this is for an in house application - so I'm not sure if it will work on other browsers).

    The approach I took was to add a LinkButton and added style='display:none;' - I set it's OnClick event to the function that I wanted the CheckBoxList to originally fire - so the LinkButton looks like this:

    <

    asp:LinkButton ID="LinkButtonCheckBoxListHack" runat="server" OnClick="RedrawGraph">HiddenCheckBoxListHack</asp:LinkButton>

    This is outside of the UpdatePanel (as is the CheckBoxList).

    I then added this to the Triggers collection for the UpdatePanel:

    <Triggers>

    <atlas:ControlEventTrigger ControlID="LinkButtonCheckBoxListHack" EventName="Click" />

    </Triggers>

    I disabled AutoPostBack on the CheckBoxList (CheckBoxListDisplayOptions) and then in the code behind file I had to do the following:

    LinkButtonCheckBoxListHack.Style[

    "display"] = "none";

    foreach (ListItem item in CheckBoxListDisplayOptions.Items)

    item.Attributes[

    "onclick"] = String.Format("{0}.click();", LinkButtonCheckBoxListHack.ClientID);

    This seems to work well for a static CheckBoxList - if you are databinding then you need to handle the CheckBoxList's OnDataBound event and put the code in there:

    protected void CheckBoxListGroups_DataBound(object sender, EventArgs e)

    {

    foreach (ListItem item in CheckBoxListGroups.Items)

    item.Attributes[

    "onclick"] = String.Format("{0}.click();", LinkButtonCheckBoxListHack.ClientID);

    }

    Hope this is of some use until this issue is resolved in future releases.  It's not ideal to have to work around such issues but it seems to work well with no adverse side effects that I have noticed!

  • Re: RadioButtonList.SelectedIndexChanged as UpdatePanel Trigger

    08-15-2006, 6:52 PM
    • Loading...
    • DamonC
    • Joined on 08-15-2006, 4:48 AM
    • Posts 2

    I've made a small update to this which allows it to work in FireFox as well - this is the update (just one line has changed).

    foreach (ListItem item in CheckBoxListDisplayOptions.Items)

    item.Attributes[

    "onclick"] = String.Format("javascript:setTimeout('__doPostBack(\\'{0}\\',\\'\\')', 0);", LinkButtonCheckBoxListHack.UniqueID);
  • Re: RadioButtonList.SelectedIndexChanged as UpdatePanel Trigger

    11-21-2006, 10:18 AM
    • Loading...
    • kilik
    • Joined on 11-02-2006, 1:59 PM
    • Posts 42

    I'm still seeing this in the latest release...is anyone else having an issue with this?

     Thanks!
     

     

     

  • Re: RadioButtonList.SelectedIndexChanged as UpdatePanel Trigger

    11-21-2006, 10:54 AM
    • Loading...
    • kilik
    • Joined on 11-02-2006, 1:59 PM
    • Posts 42
    False alarm...I'm actually seeing a different issue for which I will start a new thread.
  • Re: RadioButtonList.SelectedIndexChanged as UpdatePanel Trigger

    12-05-2006, 11:58 AM
    • Loading...
    • veloearl
    • Joined on 12-05-2006, 4:30 PM
    • Posts 52

    I can now use a RadioButtonList.SelectedIndexChanged as an asnynchronous trigger for my update panel, but I am having a strange problem.  If one of the items in the list is disabled, clicking on any of the items that come after it doesn't cause the async postback (or any postback at all).  If all of the items are enabled, clicking on any of the items causes the postback as expected.  RadioButtonList ListItems don't have a Visible property, so I have to use the Enabled property.

    Any ideas?

  • Re: RadioButtonList.SelectedIndexChanged as UpdatePanel Trigger

    08-24-2007, 1:46 PM
    • Loading...
    • hiddenkirby
    • Joined on 08-24-2007, 5:41 PM
    • Posts 1

    In my page .. as a workaround ...i put the radiobuttonlist that i was using as the target... inside its own updatepanel and set it to autopostback = True.

    Then by default all other update panels will update when another does if the UpdateMode = "Always".  The whole page did not have to postback because it was contained in the update panel.

     

    It may not be the solution for everyone, but it worked for me... and i didnt have to hack in my own javascript.

     

    -Kirb 

  • Re: RadioButtonList.SelectedIndexChanged as UpdatePanel Trigger

    09-28-2007, 1:28 PM
    • Loading...
    • wander.mahet
    • Joined on 03-31-2007, 3:42 AM
    • Rio de Janeiro
    • Posts 18

    Maybe this is also a bug in RadioButtonList

    I'm using Visual Studio 2005, Ajax (UpdatePanel), a RadioButtonList which updates a DropDownList items.

    Html code:

     
    <form id="form1" runat="server">

    <asp:ScriptManager ID="ScriptManager1" runat="server"></asp:ScriptManager>

    <asp:RadioButtonList ID="rblType" runat="server" AutoPostBack="True" OnSelectedIndexChanged="rblType_SelectedIndexChanged" OnPreRender="rblType_PreRender" RepeatDirection="Horizontal" RepeatLayout="Flow">
    <asp:ListItem Value="1" Selected="True">National</asp:ListItem>
    <asp:ListItem Value="2">International</asp:ListItem>
    </asp:RadioButtonList>

    <asp:UpdatePanel ID="udpChannel" runat="server" ChildrenAsTriggers="False" RenderMode="Inline" UpdateMode="Conditional">
    <ContentTemplate>
    <asp:DropDownList ID="ddlChannel" runat="server" AutoPostBack="True" OnSelectedIndexChanged="ddlChannel_SelectedIndexChanged"></asp:DropDownList>
    </ContentTemplate>
    <Triggers>
    <asp:AsyncPostBackTrigger ControlID="rblType" EventName="SelectedIndexChanged" />
    </Triggers>
    </asp:UpdatePanel>

    </form>

    the RadioButtonList is rendered as:

     

    <span id="rblType">
    <input id="rblType_0" type="radio" name="rblType" value="1" checked="checked" />
    <label for="rblType_0">National</label>
    <input id="rblType_1" type="radio" name="rblType" value="2" onclick="javascript:setTimeout('__doPostBack(\'rblType$1\',\'\')', 0)" />
    <label for="rblType_1">International</label>
    </span>
      

    You all can notice that the first radiobutton item has no onclick event. So, you're not able to verify if the first radio button item was clicked.

    The only way to have a onclick event in the RadioButtonList first item was creating a workaround in behind code:

     

    protected void rblType_PreRender(object sender, EventArgs e)
    {
    rblType.Items[0].Attributes.Add("onclick", "setTimeout('__doPostBack(\\'rblType$0\\',\\'\\')', 0)");
    }
     
    I don't know if my approach is correct. Did anyone have the same problem?

    Wander Mahet
    Rio de Janeiro, Brazil
  • Re: RadioButtonList.SelectedIndexChanged as UpdatePanel Trigger

    09-28-2007, 4:34 PM
    • Loading...
    • dojaju
    • Joined on 09-14-2007, 2:49 PM
    • Posts 26

    Somebody has already try with the new release??

    Let us know the issue.

    Thx

    Kind regards,
    Dojaju


    Dont forget to click "Mark as Answer" on the post that helped you.
    This credits that member, earns you a point and marks your thread as Resolved so we will all know you have been helped.
  • Re: RadioButtonList.SelectedIndexChanged as UpdatePanel Trigger

    10-02-2007, 4:39 PM
    • Loading...
    • dojaju
    • Joined on 09-14-2007, 2:49 PM
    • Posts 26

    Hi,

     I've still not found a way to have it work with a radiocontrol, but I've made it works with several checkboxes.

    Then it's only some code to add the same behavior as radiocontrol to the checkboxes.

     If somebody is interested in my solution, let's me know.

    Kind regards,

    Kind regards,
    Dojaju


    Dont forget to click "Mark as Answer" on the post that helped you.
    This credits that member, earns you a point and marks your thread as Resolved so we will all know you have been helped.
  • Re: RadioButtonList.SelectedIndexChanged as UpdatePanel Trigger

    10-05-2007, 4:02 PM
    • Loading...
    • Maya Danka
    • Joined on 09-22-2007, 10:03 AM
    • Posts 11

    I would be interested to learn.. I would like to have mutually exclusive boxes so If one is selected the other is deselected.  I am having a a problem with the radio button to show False or true in the boxes while in edit (detailsvis). I was trying some code to covert to boelan, etc.  but it does not realy work.  Thanks.

    Maya