Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

Cannot Obtain Selected Value from RadioButtonList within A ModalPopupExtender

Posted on 2011-02-28
5
Medium Priority
?
1,444 Views
Last Modified: 2012-05-11
Hi All,

I have 2 controls within a Panel control which is associated to a ModalPopupExtender so that the panel opens within a modal window.

The controls I have within my panel are a button and a RadioButtonList. When I fire the button Onclick event (which fires fine), I can't seem to obtain the selected value from my RadioButtonList.

I have taken out the 2 controls into a simple page and performed the same Onclick event and it works fine so I presume there is an issue with having the RadioButtonList open in a modal??

Can anyone help with a solution?

[ignore the irrelevant INT conversion as I have just extracted the relevant code from something larger]
if (RadioButtonListFonts.SelectedIndex > -1)
        {
            //get font item from db
            int intEngraveFontID = Convert.ToInt32(RadioButtonListFonts.SelectedValue);
                litChosenFontID.Text = intEngraveFontID.ToString();
            }
        }

Open in new window

0
Comment
Question by:rito1
  • 3
5 Comments
 
LVL 28

Accepted Solution

by:
strickdd earned 1000 total points
ID: 35000766
Are all the controls in the same UpdatePanel?
0
 
LVL 1

Author Comment

by:rito1
ID: 35001970
I'm not using an update panel.

Heres my code... I just can't seem to work it out.

THanks,

Rit
<%@ Page Language="C#" MasterPageFile="~/public_content.master" AutoEventWireup="true"
    CodeFile="product.aspx.cs" Inherits="product" Title="Untitled Page" ValidateRequest="false" %>

<%@ Register Assembly="AjaxControlToolkit" Namespace="AjaxControlToolkit" TagPrefix="asp" %>
<asp:Content ID="Content1" ContentPlaceHolderID="ContentPlaceHolder1" runat="Server">
    <asp:ToolkitScriptManager ID="ToolkitScriptManager1" runat="server">
    </asp:ToolkitScriptManager>
        <asp:PlaceHolder ID="PlaceHolderFonts" runat="server">
            <p>
                <asp:Label ID="lblFonts" runat="server" Text="Fonts:" AssociatedControlID="btnFonts"></asp:Label>
                <asp:ImageButton ID="btnFonts" runat="server" AlternateText="Fonts" ImageUrl="~/core_images/button_choose_font.png" />
                <asp:Literal ID="litChosenFont" runat="server"></asp:Literal>
                <asp:Literal ID="litChosenFontID" runat="server" Visible="true"></asp:Literal>
            </p>
            <p>
                <asp:Label ID="Label1" runat="server" Text="Text to be engraved:" Width="300px" AssociatedControlID="txtDesc"></asp:Label></p>
            <p class="align-center">
                <asp:TextBox ID="txtDesc" CssClass="ignore-float" runat="server" TextMode="MultiLine"></asp:TextBox>
            </p>
            <p>
                <asp:Label ID="Label2" runat="server" Text="Additional Information:" Width="300px"
                    AssociatedControlID="txtAdditionalInfo"></asp:Label></p>
            <p>
                <asp:TextBox ID="txtAdditionalInfo" CssClass="ignore-float texfield-large" runat="server"
                    TextMode="MultiLine"></asp:TextBox>
            </p>
        </asp:PlaceHolder>
    <asp:ModalPopupExtender ID="ModalPopupFonts" runat="server" PopupControlID="pnlFonts"
        TargetControlID="btnFonts" BackgroundCssClass="modal_background">
    </asp:ModalPopupExtender>
    <asp:Panel ID="pnlFonts" runat="server" CssClass="panel-fonts">
        <p class="align-right">
            <asp:ImageButton ID="btnSelectFonts" runat="server" ImageUrl="~/core_images/button_select_font.png"
                AlternateText="Close fonts" OnClick="btnSelectFonts_Click" />
        </p>
        <asp:RadioButtonList ID="RadioButtonListFonts" DataValueField="EngraveFontID" DataTextField="URL"
            runat="server" CssClass="list-fonts" RepeatLayout="Flow" RepeatColumns="2">
        </asp:RadioButtonList>
    </asp:Panel>
</asp:Content>



CODE BEHIND

protected void btnSelectFonts_Click(object sender, ImageClickEventArgs e)
{
        if (RadioButtonListFonts.SelectedIndex > -1)
        {
            litChosenFontID.Text = Convert.ToInt32(RadioButtonListFonts.SelectedValue);
        }
}

Open in new window

0
 
LVL 9

Assisted Solution

by:mayank_joshi
mayank_joshi earned 1000 total points
ID: 35005674
try using simple button instead of image button and check whether it works.
0
 
LVL 1

Author Comment

by:rito1
ID: 35011584
HI mayank_joshi,

Nope, the same is happening. Its as though the RadioButtonList control's viewstate isn't stored??

Rit
0
 
LVL 1

Author Comment

by:rito1
ID: 35011794
I'm an idiot sometimes!... I found the problem... I was populating the RadioButtonList control from my Page_Load event and I was missing the Page.IsPostBack check so everytime my button was being clicked it was just repopulating the  RadioButtonList  and clearing the currently selected item.

Thanks for you time anyway.

Rit
0

Featured Post

Efficient way to get backups off site to Azure

This user guide provides instructions on how to deploy and configure both a StoneFly Scale Out NAS Enterprise Cloud Drive virtual machine and Veeam Cloud Connect in the Microsoft Azure Cloud.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Problem Hi all,    While many today have fast Internet connection, there are many still who do not, or are connecting through devices with a slower connect, so light web pages and fast load times are still popular.    If your ASP.NET page …
Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
this video summaries big data hadoop online training demo (http://onlineitguru.com/big-data-hadoop-online-training-placement.html) , and covers basics in big data hadoop .
Integration Management Part 2
Suggested Courses
Course of the Month20 days, 22 hours left to enroll

810 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question