0

I am trying to post values from an AjaxToolKit ComboBox using ASP.NET 4.0.

Here is my code:

WebForm1

HTML

<body>
    <ajaxToolkit:ToolkitScriptManager ID="ToolkitScriptManager1" runat="server">
    </ajaxToolkit:ToolkitScriptManager>
    <div>
        <ajaxToolkit:ComboBox ID="ComboBox1" runat="server">
        </ajaxToolkit:ComboBox>
        <asp:Button ID="Button1" runat="server" Text="Button" UseSubmitBehavior="true" PostBackUrl="~/WebForm2.aspx" />
    </div>
</body>

C#

protected void Page_Load(object sender, EventArgs e)
{
    for (int i = 0; i < 5; i++)
    {
        ListItem tmpListItem = new ListItem("Item " + i.ToString());
        tmpListItem.Value = "Item " + i.ToString();
        ComboBox1.Items.Add(tmpListItem);
    }
}

WebForm2

C#

protected void Page_Load(object sender, EventArgs e)
{
    HttpContext tmpHttpContext = HttpContext.Current;
    string cmboBoxValue = tmpHttpContext.Request["ComboBox1"];
}

All I get for cmboBoxValue is null.

I am so frusterated because I know this must be simple. I am sure I have done this 100* in the past.

I looked here

How to submit http form using C#

but that did not help. It has to be submitted with the asp:Button.

Hopefully this is enough information for you to provide a response.

Thank you for your time.

Community
  • 1
  • 1
Steve
  • 652
  • 3
  • 11
  • 23

2 Answers2

0

Provided code below:

Put this code on default.aspx page

<cc1:ComboBox ID="ComboBox1" runat="server" AutoCompleteMode="Suggest" AutoPostBack="True" DropDownStyle="Simple">
<asp:ListItem>India</asp:ListItem>
<asp:ListItem>Lanka</asp:ListItem>
<asp:ListItem>Pak</asp:ListItem>
<asp:ListItem>Aus</asp:ListItem>
<asp:ListItem>Aps</asp:ListItem>
</cc1:ComboBox>

Put this code on button1 click event

protected void Button1_Click(object sender, EventArgs e)
    {        
         Label1.Text = "You selected" + ComboBox1.SelectedItem.Text;       
    }

You can as well check out the link below and work on your CSS page. (read the answer thats checked off)

AjaxControlToolkit, ComboBox style

Community
  • 1
  • 1
LOZ
  • 1,169
  • 2
  • 16
  • 43
0

With the help of another member I was able to uncover the answer. It can be found here:

Get POST Values in ASP.NET using NameValueCollection

Community
  • 1
  • 1
Steve
  • 652
  • 3
  • 11
  • 23