Search code examples
c#.netumbracoascx

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;
    }
}

Solution

  • Solved it! Turns out the jquery.linkselect-1.2.07.min.js library was doing something with the DropDownList that broke it. Took that out and it worked.