Solved

Cannot Obtain Selected Value from RadioButtonList within A ModalPopupExtender

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

Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
daypilot scheduler 3 26
Media.Imaging 1 18
Hey Audio! 3 28
What can cause the styling on a .NET site to not be found? 17 24
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 …
Wouldn’t it be nice if you could test whether an element is contained in an array by using a Contains method just like the one available on List objects? Wouldn’t it be good if you could write code like this? (CODE) In .NET 3.5, this is possible…
This Micro Tutorial demonstrates using Microsoft Excel pivot tables, how to reverse engineer competitors' marketing strategies through backlinks.
Established in 1997, Technology Architects has become one of the most reputable technology solutions companies in the country. TA have been providing businesses with cost effective state-of-the-art solutions and unparalleled service that is designed…

785 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