RadioButtonList inside UpdatePanel inside repeater, can I?

I have a repeater with a RadioButtonList inside an ItemTemplate, but when the RadioButtonList.OnSelectedIndexChanged event fires, it generates a full postback. What did I do wrong in my code below? How can I get OnSelectedIndexChanged to create a reverse copy of Async?

<asp:UpdatePanel runat="server" ID="UpdatePanel2">
    <ContentTemplate>
        <asp:Repeater ID="Repeater1" runat="server" DataSourceID="sqlOptions">
            <ItemTemplate>
                <asp:UpdatePanel runat="server" ID="pnlA">
                    <ContentTemplate>
                        <strong>
                            <%# Eval("Name") %></strong><br />
                        <asp:RadioButtonList ID="RadioButtonList1" 
                             DataSourceID="sqlOptionValues" runat="server"
                             DataTextField="id" DataValueField="Id" AutoPostBack="true" 
                             OnSelectedIndexChanged="LoadPrice"
                             ValidationGroup="options" />
                        <asp:RequiredFieldValidator ID="RequiredFieldValidator1" 
                             ForeColor="Red" runat="server" 
                             ControlToValidate="RadioButtonList1" 
                             ErrorMessage="Required Field" 
                             ValidationGroup="options" />
                        <asp:SqlDataSource ID="sqlOptionValues" runat="server" 
                             ConnectionString="<%$ ConnectionStrings:
                                 ConnectionString6 %>"
                             SelectCommand='<%# "SELECT DISTINCT OptionValue.Name,
                                 OptionValue.Id FROM CombinationDetail 
                                 INNER JOIN OptionValue 
                                 ON CombinationDetail.OptionValueId = OptionValue.Id 
                                 WHERE (OptionValue.OptionId =" + 
                                 Eval("Id") + ")" %>'>
                        </asp:SqlDataSource>
                        <br />
                    </ContentTemplate>
                </asp:UpdatePanel>
            </ItemTemplate>
        </asp:Repeater>
    </ContentTemplate>
</asp:UpdatePanel>

Thanks so much for any help :)

+3
source share
2 answers

. , Ajax , , . , , Accordion RadioButtonList (RBL). RBL . . , , , . , , Ajax Control Toolkit. , (http://blog.smarx.com/posts/the-case-of-the-radiobuttonlist-half-trigger.aspx), 2007 , , , .

, , , - . , , onclick RBL, . Visible = false, . : none; , , - , , , . Autopostback = "True" RBL.

CAVEAT: onclick, RBL, . , onclick AsyncPostBack, codebehind , , , . , : Page_Load(), rbl_Questions_SelectedIndexChanged() , RBL . .

:

- .Aspx:

<asp:UpdatePanel ID="UpdatePanel1" runat="server">  
    <ContentTemplate>

        <asp:RadioButtonList ID="rbl_Questions" runat="server"
            OnSelectedIndexChanged="rbl_Questions_SelectedIndexChanged">
        </asp:RadioButtonList>

        <asp:Button ID="btn_rbl_Questions" runat="server" style="display:none;"/>

        <asp:Label ID="lbl_Result" runat="server" Text="" Visible="false">
        </asp:Label>
    </ContentTemplate>  
</asp:UpdatePanel>

Page_Load():

protected void Page_Load(object sender, EventArgs e)
{
    if (IsPostBack == false)
    {
        //Instead of using the AutoPostback of the RBL, use this instead.
        rbl_Questions.Attributes.Add("onclick",
            "document.getElementById('"
            + btn_rbl_Questions.ClientID
            + "').click();");
        //Bind your RBL to a DataSource, add items programmatically,
        //  or add them in the aspx markup.
    }
}

rbl_Questions_SelectedIndexChanged():

protected void rbl_Questions_SelectedIndexChanged(object sender, EventArgs e)
{
    //Your code here.
    //My code unhid the lbl_Result control and set its text value.
}


05/24/2011

" hack" ( , ). , SO :
 Updatepanel postback asyncpostback

, , Page_Load(), , Aspx, ClientIDMode = "AutoID" AutoPostBack = "True" , UpdatePanel .

- .Aspx:

<asp:UpdatePanel ID="UpdatePanel1" runat="server">  
    <ContentTemplate>

        <asp:RadioButtonList ID="rbl_Questions" runat="server"
            ClientIDMode="AutoID" AutoPostBack="true"
            OnSelectedIndexChanged="rbl_Questions_SelectedIndexChanged">
        </asp:RadioButtonList>

        <asp:Label ID="lbl_Result" runat="server" Text="" Visible="false">
        </asp:Label>
    </ContentTemplate>  
</asp:UpdatePanel>

MS ClientID .net 4.0 "AutoID" "", , ScriptManager UpdatePanel , . , , .

+10

winforms.

:

<asp:UpdatePanel runat="server" UpdateMode="Conditional" ID="pnlA">

<Triggers>
 //radio buttons
</Triggers>

, , .

+1

All Articles