Find a HTML control using FindControl in ASP.NET
Posted
by Yongwei Xing
on Stack Overflow
See other posts from Stack Overflow
or by Yongwei Xing
Published on 2010-04-01T08:13:51Z
Indexed on
2010/04/01
8:23 UTC
Read the original article
Hit count: 554
ASP.NET
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
© Stack Overflow or respective owner