Click here to Skip to main content
15,895,084 members
Please Sign up or sign in to vote.
3.00/5 (1 vote)
See more:
I have a HTML select control in ASP.Net WebForm application. Its option values are added from jquery in client side. I would like to read those values from server side when the page is posted back. I have the following code, but it does not work. Option values added from client side are not available in code behind. How can i make those values available to code behind?

//Client code
HTML
<select title="Select one" id="selectBooks" multiple="multiple">
     <option value="1">test</option> //added in client side.
<select>


//Code behind
C#
System.Web.UI.HtmlControls.HtmlSelect books= (System.Web.UI.HtmlControls.HtmlSelect)form1.FindControl("selectBooks");
foreach (ListItem item in books.Items)
{
   string test = item.Text.ToString();
}
Posted
Updated 30-Sep-13 20:49pm
v3

Hello there,

FindControl only works if you are trying to find a Server Control (a control with attribute runat="server") and your select is an HTML control.

You can access it from the Server Side with and without using FindControl, if you add a runat="server" attribute to it.


Hope it helps

Azee...
 
Share this answer
 
v4
I think you need to use RegsiterStartupScript to call javascript function form server side.
Like this you can use.

ClientScript.RegisterStartupScript(GetType(),"id","callMyJSFunction()",true);


-SG
 
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