Solved

Cannot Obtain Selected Value from RadioButtonList within A ModalPopupExtender

Posted on 2011-02-28
5
1,428 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Get Actionable Data from Your Monitoring Solution

Your communication platform is only as good as the relevance of the information you send. Ensure your alerts get to the right people every time with actionable responses. Create escalation rules that ensure everyone follows the process and nothing is left to chance.

Question has a verified solution.

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

A long time ago (May 2011), I have written an article showing you how to create a DLL using Visual Studio 2005 to be hosted in SQL Server 2005. That was valid at that time and it is still valid if you are still using these versions. You can still re…
International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
There are cases when e.g. an IT administrator wants to have full access and view into selected mailboxes on Exchange server, directly from his own email account in Outlook or Outlook Web Access. This proves useful when for example administrator want…
Do you want to know how to make a graph with Microsoft Access? First, create a query with the data for the chart. Then make a blank form and add a chart control. This video also shows how to change what data is displayed on the graph as well as form…

690 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