Click here to Skip to main content
15,887,214 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
i have CreateUserWizard and use any asp control into this.
such as asp:textbox and...
and i find my custom control for below command:

C#
TextBox MobileTxt = CreateUserWizard1.CreateUserStep.ContentTemplateContainer.FindControl("MobileTxt") as TextBox;


and now i use this tag in CreateUserWizard:

ASP.NET
<select size="1" name="city" id="city_id" runat="server">
    <option selected="selected" value="">please select your city</option>
</select>


how i can find my <select> tag and get selected value in c#?

and i don't want use asp:drowpdownlist
Posted

Hi,

Try this:
C#
string selectedOptionValue = city_id.Items[city_id.SelectedIndex].Value;
string selectedOptionText = city_id.Items[city_id.SelectedIndex].Text;

Hope this helps.
 
Share this answer
 
Comments
SadeqHatami 17-Aug-13 4:37am    
protected void CreateUserWizard1_CreatedUser(object sender, EventArgs e)
{string selectedOptionValue = city_id.Items[city_id.SelectedIndex].Value;
}
when i do this, i get this error
"The name city-_id does not exist in the current context,
Thomas Daniels 17-Aug-13 4:43am    
You need to change city_id into the ID of your select tag. Also, you should add runat="server" to the select tag if it's not yet added.
SadeqHatami 17-Aug-13 4:50am    
i do it
<select size="1" name="city" ID="city_id" runat="server">
<option selected="selected" value="">please select your city</option>
</select>
but not work :(
Thomas Daniels 17-Aug-13 4:53am    
Can you show all the code in your body tag?
SadeqHatami 17-Aug-13 5:31am    
i try this but my body tage is big and can't show this place...

i use CreateUserWizard1 and in <asp:CreateUserWizardStep> i use <select size="1" name="city" id="city_id" runat="server">
<option selected="selected" value="">select your city</option>
</select>
and in c# code:
protected void CreateUserWizard1_CreatedUser(object sender, EventArgs e)
{ string selectedOptionValue = ostan_id.Items[ostan_id.SelectedIndex].Value;
}
and get this error:
The name city_id does not exist in the current context,
var control= Request.Form["someId"];


for more details refered to below link:
http://stackoverflow.com/questions/4351361/accessing-client-side-dynamic-controls-within-asp-net-codebehind[^]
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900