Wrox Programmer Forums
Go Back   Wrox Programmer Forums > ASP.NET and ASP > ASP.NET 1.0 and 1.1 > ASP.NET 1.0 and 1.1 Basics
|
ASP.NET 1.0 and 1.1 Basics ASP.NET discussion for users new to coding in ASP.NET 1.0 or 1.1. NOT for the older "classic" ASP 3 or the newer ASP.NET 2.0.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the ASP.NET 1.0 and 1.1 Basics section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old March 7th, 2004, 01:02 PM
Authorized User
 
Join Date: Feb 2004
Posts: 42
Thanks: 0
Thanked 0 Times in 0 Posts
Default Dynamic generation of controls in ASP.NET

I have managed to write a code that could generate textboxes on-the-fly.
The code is given below:
<script language="vb" runat="server">
Sub Page_Load()
Dim num as Integer
Dim counter as Integer

If Request.Form("select")<>"" Then
    num=Request.Form("select")
    Message.Text=""
    For counter = 1 To num
        Message.Text=Message.Text & _
        "<table><tr><td>Name</td><td><input type=text id=txtName></td></tr><tr><td>Email</td><td><input type=text name=txtEmail><td/></tr></table>"

    Next counter

End If
End Sub
</script>


<html>
    <head></head>
    <body>
        Enter the number of attendances
        <br/>
        <form runat="server">
        <asp:label id="Message" runat="server"/>
            <asp:DropDownList id="select" runat="server">
                <asp:listitem value=1/>
                <asp:listitem value=2/>
                <asp:listitem value=3/>
                <asp:listitem value=4/>
                <asp:listitem value=5/>
                <asp:listitem value=6/>
            </asp:DropDownList>
        </br>
        <input type="submit" value="Select" id="smt">
        </form>
    </body>
</html>


Could someone tell me how to get the data from these dynamically created texboxes.

&nbsp;&nbsp;CEO InteliSoft

Maqsood ur Rahman
__________________
&nbsp;&nbsp;&nbsp;CEO
InteliSoft

Maqsood ur Rahman
Life:An Endless Journey towards Perfection
 
Old March 7th, 2004, 01:32 PM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 440
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Well, first of all you have to give them a unique ID, so that you can tell one from the other, e.g. use the counter to append the current ID.

Then you will be able to retrieve the values from a form just as you are used to!

By the way... You might consider doing the text boxes really dynamically; i.e. using the objects Table, HtmlInputText etc. and add the table to the form!

Hope it helps.

Jacob.

 
Old March 8th, 2004, 07:29 PM
planoie's Avatar
Friend of Wrox
 
Join Date: Aug 2003
Posts: 5,407
Thanks: 0
Thanked 16 Times in 16 Posts
Default

Maxood,

Building dynamic controls the way you are doing it kind of defeats the purpose and power of ASP.NET. As Jacob suggested, you should use ASP.NET server controls. This way you have the power of those controls at your disposal. Otherwise, you are just scripting like you did in ASP. With the right coding you should never have to access the Request.Form() collection.

Peter
------------------------------------------------------
Work smarter, not harder.





Similar Threads
Thread Thread Starter Forum Replies Last Post
Creating Dynamic ASP.NET Server Controls Using XML kwilliams XSLT 0 October 6th, 2006 01:42 PM
Dynamic generation of .Net button in a position sonaldewle General .NET 0 April 3rd, 2006 03:51 AM
Dynamic generation of asp.net server controls shashi1312 Classic ASP XML 1 August 2nd, 2005 04:52 AM
Dynamic ASP button generation Lloyd_Christmas Classic ASP Basics 1 May 17th, 2005 06:50 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.