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.

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)
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.