Find a HTML control using FindControl in ASP.NET
- by Yongwei Xing
Hi akk
I add a select control to a ASPX page like below:
hgc = new HtmlGenericControl();
hgc.InnerHtml = @"<select runat='server' id='my_selectlist'> \
<option value='volvo'>Volvo</option> \
<option value='saab'>Saab</option> \
<option value='mercedes'>Mercedes</option> \
<option value='audi'>Audi</option> \
</select>";
Then in a Button click event, I use the code below, try to get the value selected
HtmlSelect s = (HtmlSelect)hgc.FindControl("my_selectlist");
label.Text = s.Value;
I get a error:"Object reference not set to an instance of an object."
Does anyone try it before?
Best Regards