So I have 2 pages. They both have the same master page and are part of the same Web Application. I am trying to submit one page to the other. On the submitting page I have a few elements such as
<ajaxToolkit:ComboBox ID="cmboOptions" AutoCompleteMode="SuggestAppend"
CaseSensitive="false" ItemInsertLocation="Append" runat="server" DropDownStyle="DropDownList">
<asp:ListItem></asp:ListItem>
<asp:ListItem Text="Option 1" Value="opt1"></asp:ListItem>
<asp:ListItem Text="Option 2" Value="opt2"></asp:ListItem>
</ajaxToolkit:ComboBox>
I am using
<asp:Button ID="btnSubmit" runat="server" Text="Submit"
PostBackUrl="~/Results.aspx" />
to submit the page.
On the results page in the code behind on page load I have
NameValueCollection nvc = Request.Form;
string selectedOption = nvc["cmboOptions"];
If I look in the NVC on debug I can see
ctl00$MainContent$cmboOptions$TextBox
with a value of "Option 1" yet my string still contains a value of null. I do not want to even bother trying to get the value by hard coding the obfuscated ID's in and I can't set a name property on ASP.net elements.
Does anyone know a better/proper way to accomplish what I am doing? I would like to stick with the ajaxControlToolkit comboboxes because they are nice for the user although I wish I stuck with jQuery instead of listening to my friend and now it's too late to switch.
I looked here without any luck
and here
Read Post Data submitted to ASP.Net Form
and here
http://msdn.microsoft.com/en-us/library/6c3yckfw.aspx
and I tried PreviousPage.FindControl and I always get null.
Thanks for your time!
Edit:
Avoid the AjaxControlToolKit. It is nice if you want to be lazy and drag->drop sweet UI elements but is just a headache to get simple things working! Use jQuery.
I think you have to use Page.PreviousPage Property You can get the dropdown value as
Read more on msdn about Cross Page Posting in Asp.net
Updated Answer: To check the Steve code I created a page with a dropdownlist and a button to do postback ( Currently I don't have ajaxtoolkit so I'm using dropdownlist )
So, i think the problem is with the Ajax Combo box.( if you are not doing any mistake )
Updated Answer: The problem is that the ID of Ajax Combo box control is changed when we post the page. In the Next page we can get the ID of ajax combox box as
For Pages Without Master Pages: If you are using an aspx page without master page then you can get the ID of ajax combo box as
For Pages using MasterPages: