Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Dean 2 posts 22 karma points
    May 11, 2012 @ 15:35
    Dean
    0

    Getting SelectedValue from a DropDownList

    I am trying to create a basic macro that encapsulates a form and the ability to email the details entered into it. It works fine for Textboxes, but for some reason the DropDownLists take the first value in the list of options. I've been working on this for hours and seem to've tried everything, so hopefully someone can suggest a solution. I am using Umbraco 4.0.3 and unfortunately upgrade is not an option. My reduced code is as follows:

    CorpRefundForm.ascx:

    <%@ Control Language="C#" AutoEventWireup="true" CodeFile="CorpRefundForm.ascx.cs" Inherits="umbracowebsitewizard_site.Usercontrols.CorpRefundForm" %>

    <asp:DropDownList ID="frm_dropdown" runat="server" CssClass="linkselect" />

    <br />

    <button id="submitButton" runat="server" onserverclick="submitButton_Click">Submit</button>

    CorpRefundForm.ascx.cs

    using System;
    using System.Net.Mail;
    using System.Web.UI;
    using System.Web.UI.WebControls;

    namespace umbracowebsitewizard_site.Usercontrols
    {
    public partial class CorpRefundForm : UserControl
    {
    protected void Page_Init(object sender, EventArgs e)
    {
    if (!Page.IsPostBack)
    {
    frm_dropdown.Items.Add(new ListItem("Select one", ""));
    frm_dropdown.Items.Add(new ListItem("One", "One"));
    frm_dropdown.Items.Add(new ListItem("Two", "Two"));
    frm_dropdown.Items.Add(new ListItem("Three", "Three"));
    frm_dropdown.Items.Add(new ListItem("Four", "Four"));
    }
    }

    public void submitButton_Click(object sender, EventArgs e)
    {
    SmtpClient mySMTPClient = new SmtpClient();

    mySMTPClient.Send("[email removed]", "[email removed]", "Test", frm_dropdown.SelectedValue + frm_dropdown.Text + frm_dropdown.SelectedItem.Value + frm_dropdown.SelectedItem.Text);
    }
    }
    }

    CorpRefundForm.ascx.designer.cs:

    using System.Web.UI.WebControls;

    namespace umbracowebsitewizard_site.Usercontrols
    {
    public partial class CorpRefundForm
    {
    protected DropDownList frm_dropdown;
    }
    }

    Any help is greatly appreciated.

  • Bo Damgaard Mortensen 712 posts 1189 karma points
    May 11, 2012 @ 22:21
    Bo Damgaard Mortensen
    0

    Hi Dean,

    What happens if you switch these two:

    frm_dropdown.SelectedValue and frm_dropdown.Text

    to

    frm_dropdown.SelectedItem.Value and frm_dropdown.SelectedItem.Value

    ? :-)

  • Dean 2 posts 22 karma points
    Sep 18, 2012 @ 10:05
    Dean
    0

    Sorry, I completely forgot about this post! The problem was JS library was doing something to the Dropdown that caused it to stop working, so I removed it. Unfortunately as it has been removed I can't remember what it was, but anyone with this problem should try disabling JS!

  • This forum is in read-only mode while we transition to the new forum.

    You can continue this topic on the new forum by tapping the "Continue discussion" link below.

Please Sign in or register to post replies