Dynamically create asp:textbox

coedeed

New Member
I'm fairly new to asp.net so please have mercy. Here's the situation:<BR><BR>Webservice A (returns XmlNode) returns a list of functions that can be executed. These function names are binded to a listbox, and when the user selects a function from the listbox Webservice B is executed (with that information), and it returns (dataset) the variables (inputs) required for that specific funtion.<BR><BR>What i'm trying to do is generate asp:textboxes from the resulting dataset from webservice B. So that the inputs for the selected function are automatically generated.<BR><BR>So... in a nutshell. How would you go about generating asp:textbox(es) dynamically from information stored in a dataset?<BR><BR>A link or any other info would be greatly appreciated.<BR><BR>Thanks!<BR><BR>-LokiI played around with this some, but I found it somewhat difficult. If you dynamically create it such as <BR><BR>Dim htmlwriter As System.Web.UI.HtmlTextWriter<BR> Dim thisbox As System.Web.UI.WebControls.TextBox<BR> thisbox.RenderControl(htmlwriter)<BR><BR>but then I am assuming that it will render at the next point in the page, or you have to build and render all the objects on the page this way.<BR><BR>I would be interested to see some example code showing a good use for this.<BR><BR>-BI did find one way of doing this using the asp:placeholder. It seems to work rather well... It's elegant, and simple.<BR><BR>Here's an example:<BR><BR><%@ Page Language="C#" %><BR><BR> <script runat="server"><BR><BR> void Page_Load(Object s, EventArgs e)<BR> {<BR> HtmlButton myButton = new HtmlButton(); <BR><BR> myButton.InnerText = "First Button";<BR> button_placeholder.Controls.Add(myButton);<BR><BR> myButton = new HtmlButton();<BR> myButton.InnerText = "Second Button";<BR> button_placeholder.Controls.Add(myButton);<BR> }<BR> <BR> void create_boxes(Object s, EventArgs e)<BR> {<BR> TextBox myBox = new TextBox();<BR> <BR> myBox = new TextBox();<BR> myBox.Text = "First Text Box";<BR> box_placeholder.Controls.Add(myBox);<BR> <BR> myBox = new TextBox();<BR> myBox.Text = "Second Text Box";<BR> box_placeholder.Controls.Add(myBox);<BR> }<BR> </script><BR><BR><html><BR><body><BR> <form runat="server"><BR> <center><h3>Place Holders</h3></center><BR><BR> <asp:placeholder id="button_placeholder" runat="server"/><BR> <BR><BR><BR> <asp:button Text="Create Boxes" id="btnClick" onClick="create_boxes" runat="server" /><BR> <BR><BR><BR> <asp:placeholder id="box_placeholder" runat="server" /><BR> </form><BR></body><BR></html><BR><BR><BR>It creates standard ids for the textboxes, and if you want to change the appearance you can do so using myBox.<whatever>. Pretty cool stuff!<BR><BR>-Loki<BR>
 
Back
Top