0

All,

I am adding HTML controls with runat ="server" dynamically from my asp.net code.

<form id="frm1" runat="server">
<div>
<asp:Button ID="Button1" runat="server" Text="Button" /></div>
<div runat="Server"> <asp:PlaceHolder ID="p1" runat="server"><%=strControl%></asp:PlaceHolder></div>
</form>

The code behind has
Public strControl as New string
strControl = "<input type=""hidden"" id=""test"" value=""test1"" runat=""server""/>"

Am able to view the input hidden control when the page is rendered. On click of submit button in page am writing a code like

Dim hdn1 as New HTMLInputHidden
hdn1 = Ctype(FindControl("test"), HTMLInputHidden)

But hdn1 always returns me nothing. is it possible to get the control in the code behind? I think there has to be something missing in my code. Can anyone help?

Thanks in advance.

2
Contributors
1
Reply
2
Views
9 Years
Discussion Span
Last Post by SheSaidImaPregy
0

you cannot add the control like that. There you are just adding an attribute to the HTML input, but it is never rendered as a control. Therefore you cannot find the control on the page.

You would need something like this (untested):

Dim hdn1 As New HtmlInputHidden
hdn1.value = "test1"
Controls.Add(hdn1)

'--onclick:
Dim hdn1 As HtmlInputHidden = CType(FindCOntrol("hdn1"), HtmlInputHidden)

response.write(hdn1.value)
This topic has been dead for over six months. 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.