Solved

Cannot Obtain Selected Value from RadioButtonList within A ModalPopupExtender

Posted on 2011-02-28
5
1,396 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 250 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 250 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

Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

Join & Write a Comment

Suggested Solutions

Entity Framework is a powerful tool to help you interact with the DataBase but still doesn't help much when we have a Stored Procedure that returns more than one resultset. The solution takes some of out-of-the-box thinking; read on!
Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
Internet Business Fax to Email Made Easy - With eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.

760 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

Need Help in Real-Time?

Connect with top rated Experts

24 Experts available now in Live!

Get 1:1 Help Now