Creating a form dynamicly

Discussion in 'ASP .Net' started by DaWoE, Sep 1, 2004.

  1. DaWoE

    DaWoE Guest

    Hi all,

    I'm fairly new to ASP.NET. What i want to do is creat a online
    registration form. On the first step is getting the users details and
    the number of people he wants to register.
    Based on the number of people i want to create a form where he can enter
    the persons details.

    For example he wants to register 3 people. Then the second step of the
    registration would have to be like this :

    Person1
    Name :
    E-mail :
    Function :

    Person2
    Name :
    E-mail :
    Function :

    Person3
    Name :
    E-mail :
    Function :

    How do i create this in .NET
    I was thinking creating panels with the small forms dynamicly.
    How do i that ? Where can if find info on doing this.

    Thanks in advance

    --
    DaWoE
     
    DaWoE, Sep 1, 2004
    #1
    1. Advertising

  2. Hi DaWoE,

    Yes you are right you can use panels and depending on the number of people
    you can add the control dynamically
    to the panel and once user enters values..you can loop through the contols
    and access those values.

    but for this you need to make a post back to the server once user enters the
    number of people.

    Workaround to prevent a post back..what you can do is create some 10 div
    tags <DIV> and make them visible is false initially
    and when user enters the number of people in the TextBox ( i assume you use
    textbox ) on textChange or lost focus of text box use javascript
    to make the number of DIV tags visible = true..

    This method seems to be little difficult but prevents a post back !

    Hope this helps you.

    Thanks
    Raghavendra


    "DaWoE" <> wrote in message
    news:...
    > Hi all,
    >
    > I'm fairly new to ASP.NET. What i want to do is creat a online
    > registration form. On the first step is getting the users details and
    > the number of people he wants to register.
    > Based on the number of people i want to create a form where he can enter
    > the persons details.
    >
    > For example he wants to register 3 people. Then the second step of the
    > registration would have to be like this :
    >
    > Person1
    > Name :
    > E-mail :
    > Function :
    >
    > Person2
    > Name :
    > E-mail :
    > Function :
    >
    > Person3
    > Name :
    > E-mail :
    > Function :
    >
    > How do i create this in .NET
    > I was thinking creating panels with the small forms dynamicly.
    > How do i that ? Where can if find info on doing this.
    >
    > Thanks in advance
    >
    > --
    > DaWoE
     
    Raghavendra T V, Sep 1, 2004
    #2
    1. Advertising

  3. DaWoE

    DaWoE Guest

    Hi Raghavendra,

    I did use a postpack. Here is the testcode that worked for me.

    The aspx file :
    <%@ Page Language="vb" AutoEventWireup="false" Codebehind="test.aspx.vb"
    Inherits="PlayInn.test"%>
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
    <HTML>
    <HEAD>
    <title>test</title>
    <meta name="GENERATOR" content="Microsoft Visual Studio .NET 7.1">
    <meta name="CODE_LANGUAGE" content="Visual Basic .NET 7.1">
    <meta name="vs_defaultClientScript" content="JavaScript">
    <meta name="vs_targetSchema"
    content="http://schemas.microsoft.com/intellisense/ie5">
    </HEAD>
    <body MS_POSITIONING="FlowLayout">
    <form id="Form1" method="post" runat="server">
    <asp:panel id="Panel1" runat="server">
    <asp:TextBox id="TextBox1" runat="server"></asp:TextBox>
    <asp:Button id="Button1" runat="server" Text="Button"></asp:Button>
    </asp:panel>
    <asp:panel id="Panel2" runat="server" Visible="False">
    <asp:Button id="Button2" runat="server" Text="Button"></asp:Button>
    </asp:panel>
    </form>
    </body>
    </HTML>


    The vb.file :
    Public Class test
    Inherits System.Web.UI.Page

    #Region " Web Form Designer Generated Code "

    'This call is required by the Web Form Designer.
    <System.Diagnostics.DebuggerStepThrough()> Private Sub
    InitializeComponent()

    End Sub
    Protected WithEvents Panel1 As System.Web.UI.WebControls.Panel
    Protected WithEvents TextBox1 As System.Web.UI.WebControls.TextBox
    Protected WithEvents Button1 As System.Web.UI.WebControls.Button
    Protected WithEvents Panel2 As System.Web.UI.WebControls.Panel
    Protected WithEvents Button2 As System.Web.UI.WebControls.Button

    'NOTE: The following placeholder declaration is required by the Web
    Form Designer.
    'Do not delete or move it.
    Private designerPlaceholderDeclaration As System.Object

    Private Sub Page_Init(ByVal sender As System.Object, ByVal e As
    System.EventArgs) Handles MyBase.Init
    'CODEGEN: This method call is required by the Web Form Designer
    'Do not modify it using the code editor.
    InitializeComponent()
    End Sub

    #End Region

    Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
    System.EventArgs) Handles MyBase.Load
    'Put user code to initialize the page here
    End Sub
    Protected Overrides Sub LoadViewState(ByVal savedState As Object)
    MyBase.LoadViewState(savedState)
    If ViewState("controlsadded") = True Then
    AddControls()
    End If
    End Sub

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
    System.EventArgs) Handles Button1.Click
    Dim liNumber As Int32
    Dim liCount As Int32
    Dim loLabel As Label
    Dim loControl As Control

    liNumber = CType(TextBox1.Text, Int32)
    Session("Number") = liNumber
    If ViewState("controlsadded") Is Nothing Then
    AddControls()
    End If

    For liCount = 1 To liNumber
    loLabel = New Label
    loLabel = CType(Panel2.FindControl("label" & liCount), Label)
    loLabel.Text = "This label" & liCount
    Next
    Panel1.Visible = False
    Panel2.Visible = True
    End Sub

    Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As
    System.EventArgs) Handles Button2.Click
    Dim liCount As Int32
    Dim loLabel As Label

    For liCount = 1 To CType(TextBox1.Text, Int32)
    loLabel = New Label
    Try
    loLabel = CType(Panel2.FindControl("label" & liCount),
    Label)
    Response.Write("Label" & liCount & ".text = " &
    loLabel.Text & "<br>")
    Catch ex As Exception
    Response.Write(ex.Message & "<br>")
    End Try
    Panel2.Visible = False
    Next
    End Sub
    Private Sub AddControls()
    Dim liNumber As Int32
    Dim liCount As Int32
    Dim loLabel As Label

    liNumber = Session("Number")

    For liCount = 1 To liNumber
    loLabel = New Label
    loLabel.ID = "label" & liCount
    loLabel.EnableViewState = True
    Panel2.Controls.AddAt(liCount - 1, loLabel)
    Next
    ViewState("controlsadded") = True
    End Sub
    End Class



    >Raghavendra T V wrote:
    > Hi DaWoE,
    >
    > Yes you are right you can use panels and depending on the number of people
    > you can add the control dynamically
    > to the panel and once user enters values..you can loop through the contols
    > and access those values.
    >
    > but for this you need to make a post back to the server once user enters the
    > number of people.
    >
    > Workaround to prevent a post back..what you can do is create some 10 div
    > tags <DIV> and make them visible is false initially
    > and when user enters the number of people in the TextBox ( i assume you use
    > textbox ) on textChange or lost focus of text box use javascript
    > to make the number of DIV tags visible = true..
    >
    > This method seems to be little difficult but prevents a post back !
    >
    > Hope this helps you.
    >
    > Thanks
    > Raghavendra
    >
    >
    > "DaWoE" <> wrote in message
    > news:...
    >
    >>Hi all,
    >>
    >>I'm fairly new to ASP.NET. What i want to do is creat a online
    >>registration form. On the first step is getting the users details and
    >>the number of people he wants to register.
    >>Based on the number of people i want to create a form where he can enter
    >>the persons details.
    >>
    >>For example he wants to register 3 people. Then the second step of the
    >>registration would have to be like this :
    >>
    >>Person1
    >>Name :
    >>E-mail :
    >>Function :
    >>
    >>Person2
    >>Name :
    >>E-mail :
    >>Function :
    >>
    >>Person3
    >>Name :
    >>E-mail :
    >>Function :
    >>
    >>How do i create this in .NET
    >>I was thinking creating panels with the small forms dynamicly.
    >>How do i that ? Where can if find info on doing this.
    >>
    >>Thanks in advance
    >>
    >>--
    >>DaWoE

    >
    >
    >
     
    DaWoE, Sep 1, 2004
    #3
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. =?Utf-8?B?WWFuaXI=?=

    Dynamicly get the form name at server

    =?Utf-8?B?WWFuaXI=?=, Apr 19, 2004, in forum: ASP .Net
    Replies:
    1
    Views:
    293
    bruce barker
    Apr 19, 2004
  2. Owen Wong
    Replies:
    0
    Views:
    337
    Owen Wong
    Sep 12, 2006
  3. robk

    OnItemDataBound - creating dynamicly radiobuttonlist

    robk, Jul 20, 2005, in forum: ASP .Net Datagrid Control
    Replies:
    0
    Views:
    301
  4. Vasko Buraliev

    creating interface dynamicly

    Vasko Buraliev, Sep 22, 2003, in forum: ASP .Net Web Controls
    Replies:
    1
    Views:
    141
    Ravikanth[MVP]
    Sep 22, 2003
  5. Adding form fields dynamicly

    , Jan 21, 2005, in forum: Javascript
    Replies:
    1
    Views:
    100
    Martin Honnen
    Jan 21, 2005
Loading...

Share This Page