0

Hello
I made a web page that needs the user to insert some info in text boxes and then submit them .
I want to ask about how can i insert as an option to drop down list once i enter the textbox value by the user like this

NAME <input type ="text" id="name"/>
<asp:DropDownList ID="Namelist" runat="server">
<asp:ListItem>new user </asp:ListItem>
<asp:ListItem > the text taken from the textbox </asp:ListItem>
</asp:DropDownList>

NOW , I want to do it using jquery ( info.aspx ) file or in the behind code , i tried to do the behind code in c# but the id of the text box isnt recognizable a syntax error pops up says that its not in the context ..all what i saw while searching was inserting to the drop down list after button click event ...but i dont want this . in the user ( info.aspx.cs) file behind code i tried this

protected void NameList_SelectedIndexChanged(object sender, EventArgs e)
{
NameList.Items.Add( name.Text);
}

but the id of the "name" text box doesnt exist in the current context ,also i tried to add it as an option

NameList.Items.Add(new ListItem (name.Text));

For the date elements this worked

day.InnerText = DateTime.Today.ToString("dddd");//show day in label day
timeDate.InnerText = DateTime.Today.ToString("MM/dd/yyyy");// show date in label time date

but to fill the drop down list it didnt work! any idea how to fill it when the user select from the list's options? thanks

Edited by fedaa91

2
Contributors
3
Replies
19
Views
3 Years
Discussion Span
Last Post by fedaa91
0

If you want access to the input element from your code behind, use a textbox control instead.

<asp:TextBox ID="name" runat="server"></asp:TextBox>

or you would have to add the runat="server" property to your input element.

0

ok , i will do this and see what happens ...thank you so much

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.