| | |
Adding HTML controls dynamically in asp.net page
Please support our ASP.NET advertiser: Intel Parallel Studio Home
![]() |
•
•
Join Date: Feb 2008
Posts: 1
Reputation:
Solved Threads: 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
laceHolder ID="p1" runat="server"><%=strControl%></asp
laceHolder></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.
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
laceHolder ID="p1" runat="server"><%=strControl%></asp
laceHolder></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.
•
•
Join Date: Sep 2007
Posts: 1,080
Reputation:
Solved Threads: 68
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):
You would need something like this (untested):
ASP.NET Syntax (Toggle Plain Text)
Dim hdn1 As New HtmlInputHidden hdn1.value = "test1" Controls.Add(hdn1) '--onclick: Dim hdn1 As HtmlInputHidden = CType(FindCOntrol("hdn1"), HtmlInputHidden) response.write(hdn1.value)
![]() |
Similar Threads
- Adding Controls Dynamically (URGENT) (ASP.NET)
Other Threads in the ASP.NET Forum
- Previous Thread: The textField is preserving it data!!!!
- Next Thread: Problem using String.Format inside Request.Form
| Thread Tools | Search this Thread |
Tag cloud for ASP.NET
.net 2.0 activexcontrol ajax alltypeofvideos anathor appliances application asp asp.net bc30451 beginner box browser button c# cac checkbox commonfunctions complex dataaccesslayer database datagridview datagridviewcheckbox datalist development dgv dialog dropdownlist dynamically edit editing expose feedback fileuploader fill flash form formatdecimal formview google gridview gudi iis image javascript list listbox login microsoft migration mouse mssql news numerical opera panelmasterpagebuttoncontrols parent problem project radio redirect registration relationaldatabases reportemail response.redirect richtextbox rows save schoolproject search security select session sessionvariables silverlight smartcard smoobjects software sql-server sqlserver2005 suse textbox tracking treeview unauthorized validatedate validation vb.net video videos vista visualstudio web webapplications webdevelopemnt webprogramming webservice xsl youareanotmemberofthedebuggerusers






