Click here to Skip to main content
15,069,838 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.
   
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,
Thomas Daniels 17-Aug-13 5:33am
   
In your code, you use ostan_id but if you use ostan_id, then you should change the id of the select tag into ostan_id
SadeqHatami 17-Aug-13 6:02am
   
i change it but i get same error
Thomas Daniels 17-Aug-13 6:10am
   
I get no error. I'm sorry, but I've no idea what's wrong.
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[^]
   

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