[Last Call] Learn about multicloud storage options and how to improve your company's cloud strategy. Register Now

x
?
Solved

Cannot Obtain Selected Value from RadioButtonList within A ModalPopupExtender

Posted on 2011-02-28
5
Medium Priority
?
1,440 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 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

What’s Wrong with Your Cloud Strategy ?

Even as many CIOs are embracing a cloud-first strategy, the reality is that moving to the cloud is a lengthy process and the end-state is likely to be a blend of multiple clouds—public and private. Learn why multicloud solutions matter in this webinar by Nimble Storage.

Question has a verified solution.

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

More often than not, we developers are confronted with a need: a need to make some kind of magic happen via code. Whether it is for a client, for the boss, or for our own personal projects, the need must be satisfied. Most of the time, the Framework…
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…
Visualize your data even better in Access queries. Given a date and a value, this lesson shows how to compare that value with the previous value, calculate the difference, and display a circle if the value is the same, an up triangle if it increased…
How to fix incompatible JVM issue while installing Eclipse While installing Eclipse in windows, got one error like above and unable to proceed with the installation. This video describes how to successfully install Eclipse. How to solve incompa…

650 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