Access dynamically generated control from code behind
Posted
by
user648922
on Stack Overflow
See other posts from Stack Overflow
or by user648922
Published on 2012-10-18T22:52:32Z
Indexed on
2012/10/19
5:02 UTC
Read the original article
Hit count: 134
I load a piece of html which contains something like:
<em> < input type="text" value="Untitled" name="ViewTitle" id="ViewTitle" runat="server"> </em>
into my control. The html is user defined, do please do not ask me to add them statically on the aspx page.
On my page, I have a placeholder and I can use
LiteralControl target = new LiteralControl ();
// html string contains user-defined controls
target.text = htmlstring
to render it property. My problem is, since its a html piece, even if i know the input box's id, i cannot access it using FindControl("ViewTitle")
(it will just return null) because its rendered as a text into a Literal control and all the input controls were not added to the container's control collections. I definitely can use Request.Form["ViewTitle"]
to access its value, but how can I set its value?
© Stack Overflow or respective owner