Velocity Reviews

Velocity Reviews (http://www.velocityreviews.com/forums/index.php)
-   ASP .Net (http://www.velocityreviews.com/forums/f29-asp-net.html)
-   -   Creating a form dynamicly (http://www.velocityreviews.com/forums/t85871-creating-a-form-dynamicly.html)

DaWoE 09-01-2004 09:06 AM

Creating a form dynamicly
 
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 09-01-2004 10:03 AM

Re: Creating a form dynamicly
 
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" <dawoe2000@yahoo.com> wrote in message
news:2plhp9Fmg2e3U1@uni-berlin.de...
> 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 09-01-2004 10:39 AM

Re: Creating a form dynamicly
 
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" <dawoe2000@yahoo.com> wrote in message
> news:2plhp9Fmg2e3U1@uni-berlin.de...
>
>>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

>
>
>



All times are GMT. The time now is 03:46 PM.

Powered by vBulletin®. Copyright ©2000 - 2014, vBulletin Solutions, Inc.
SEO by vBSEO ©2010, Crawlability, Inc.