ASP.NET Code
  Home arrow ASP.NET Code arrow Create form Wizard using Code-Behind
ASP Free Forums 
.NET  
ASP  
ASP Code  
ASP.NET  
ASP.NET Code  
BrainDump  
C#  
Code Examples  
Database  
Database Code  
IIS  
Microsoft Access  
MS SQL Server  
Silverlight  
Visual Basic.NET  
Windows Scripting  
Windows Security  
XML  
Mobile Linux 
App Generation ROI 
IBM® developerWorks 
ASP Web Hosting  
ASP.NET Web Hosting 
Windows Web Hosting
 
Weekly Newsletter
 
Developer Updates  
Free Website Content 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Write For Us Get Paid 
Request Media Kit
Contact Us 
Site Map 
Privacy Policy 
Support 
 USERNAME
 
 PASSWORD
 
 
  >>> SIGN UP!  
  Lost Password? 
ASP.NET CODE

Create form Wizard using Code-Behind
By: aspfree
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 4 stars4 stars4 stars4 stars4 stars / 5
    2001-12-05

    Table of Contents:

    Rate this Article: Poor Best 
      ADD THIS ARTICLE TO:
      Del.ici.ous Digg
      Blink Simpy
      Google Spurl
      Y! MyWeb Furl
    Email Me Similar Content When Posted
    Add Developer Shed Article Feed To Your Site
    Email Article To Friend
    Print Version Of Article
    PDF Version Of Article
     
     
    ADVERTISEMENT



    This is a updated demo to create form wizard using an aspx page and code-behind in VB.NET


    <%@ Page Language="vb" EnableSessionState="False" EnableViewState="True" Trace="False" Debug="False" Inherits="createformcode" src="createformcode.vb" %>
    <HTML>
    <HEAD>
    <title></title>
    </HEAD>
    <body bgcolor="#ffffff">
    <form runat="server" id="form1">
    Select a tablename to create a .NET form for:
    <asp:dropdownlist id="tblList" runat="server" />&nbsp;&nbsp;
    <asp:Button id="GetTable" Text="Get Table" onclick="GetTable_Click" runat="server" />
    <asp:panel id="myPanel" runat="server" visible="false"><BR>Select the
    Columns used for generating the form.
    <asp:datagrid id="MyDataGrid" runat="server" AutoGenerateColumns="False" HeaderStyle-BackColor="#aaaadd" Font-Size="8pt" Font-Name="Verdana" CellPadding="3" BorderWidth="1" BorderColor="black">
    <Columns>
    <asp:TemplateColumn HeaderText="Add?">
    <ItemTemplate>

    <asp:CheckBox id="chkAdd" runat="server" />

    </ItemTemplate>
    </asp:TemplateColumn>
    <asp:BoundColumn HeaderText="Name" DataField="name" />
    <asp:TemplateColumn HeaderText="Create Validator?">
    <ItemTemplate>

    <asp:CheckBox id="chkValid" runat="server" />

    </ItemTemplate>
    </asp:TemplateColumn>
    </Columns>
    </asp:datagrid>
    <asp:Button id="Button1" onclick="btnSubmit_Click" runat="server" Text="Create Form"></asp:Button> </asp:panel>
    <asp:panel id="pnlTextarea" visible="false" runat="server">
    <P>Copy this code into a new ASP.NET page</P>
    <TEXTAREA id="taResults" name="taResults" rows="40" cols="90" runat="server"> &lt;/asp:panel&gt; &lt;/form&gt; &lt;/body&gt; &lt;/html&gt;
    </TEXTAREA>
    </asp:panel>
    </form>
    </body>
    </HTML>

     

    Imports System
    Imports System.Text
    Imports System.IO
    Imports System.Data
    Imports System.Data.SqlClient
    Imports System.Configuration
    Imports System.Web
    Imports System.Web.UI.WebControls
    Imports System.Web.UI.HTMLControls
    Imports Microsoft.VisualBasic

    Public Class createformcode: Inherits System.Web.UI.Page

    Protected WithEvents TextBox1 As System.Web.UI.WebControls.TextBox
    Protected WithEvents MyDataGrid As System.Web.UI.WebControls.DataGrid
    Protected WithEvents taResults As System.Web.UI.HtmlControls.HtmlTextArea
    Protected WithEvents pnlTextarea As System.Web.UI.WebControls.Panel
    Protected WithEvents myPanel As System.Web.UI.WebControls.Panel
    Protected WithEvents tblList As System.Web.UI.WebControls.DropDownList
    Protected WithEvents GetTable As System.Web.UI.WebControls.Button
    Protected WithEvents btnSubmit As System.Web.UI.WebControls.Button

    Dim sqlText As String
    Dim ds As New DataSet()
    Dim dbComm As New SqlDataAdapter()
    Dim conn As SqlConnection
    Dim sqlServer As String

    Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

    sqlServer = GetSqlConn()
    conn = New SqlConnection(sqlServer)
    If Not IsPostBack Then
    sqlText = "select id, name from sysobjects where xtype='U' order by name"
    dbComm = New SqlDataAdapter(sqlText, conn)
    dbComm.Fill(ds, "AllTables")
    tblList.DataSource = ds.Tables("AllTables").DefaultView
    tblList.DataTextField = "name"
    tblList.DataValueField = "name"
    tblList.DataBind()
    End If
    End Sub

    Function CreateValidator(ByVal myName As String) As String
    Dim mySB As StringBuilder = New StringBuilder()

    REM -- use :<some text>: as placeholders
    mySB.Append("<asp:RequiredFieldValidator runat=""server"" id="":Name:"" ControlToValidate="":control:"" ErrorMessage="":errMsg:"" display=""Static"">This Required Field!</asp:RequiredFieldValidator>")

    mySB.Replace(":Name:", "vld" & myName) 'add the validator name
    mySB.Replace(":control:", "at" & myName) 'add the control name
    mySB.Replace(":errMsg:", myName & " is required")

    Return mySB.ToString()

    End Function

    Function GetSqlConn() As String
    Dim DSN As String = ConfigurationSettings.AppSettings("DSN")
    Return DSN
    End Function

    Sub GetTable_Click(ByVal sender As Object, ByVal e As EventArgs)
    Dim sqlText As String
    sqlText = "SELECT syscolumns.name, syscolumns.isnullable FROM sysobjects INNER JOIN syscolumns ON sysobjects.id = syscolumns.id where sysobjects.name = '" & tblList.SelectedItem.Text & "' ORDER BY syscolumns.colid"

    REM -- Connect to SQL
    dbComm = New SqlDataAdapter(sqlText, conn)

    REM -- Fill DataSet
    dbComm.Fill(ds, "TestData")
    MyDataGrid.DataSource = ds.Tables("TestData").DefaultView
    MyDataGrid.DataBind()


    REM -- Show the results
    myPanel.Visible = True

    End Sub

    Public Sub btnSubmit_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)

    Dim i As Integer
    Dim _item As DataGridItem
    Dim dr As DataRow
    Dim sb As StringBuilder = New StringBuilder()
    Dim strOutput As String

    REM -- Auto Generate The Form
    sb.Append("<form runat=""server"" id=""form2"" name=""form2"">" & chr(13) & chr(10))
    sb.Append(" <table border=1>")


    For i = 0 To MyDataGrid.Items.Count - 1
    REM -- Get the checkbox
    _item = MyDataGrid.Items(i)
    Dim addCheckBox As CheckBox = Ctype(_item.FindControl("chkAdd"), CheckBox)
    Dim validCheckBox As CheckBox = Ctype(_item.FindControl("chkValid"), CheckBox)

    If addCheckBox.Checked Then
    sb.Append(" <tr>" & chr(13))
    sb.Append(" <td>" & _item.Cells(1).Text & "</td>" & chr(13))
    sb.Append(" <td>")
    sb.Append("<asp:textbox id=""at" & _item.Cells(1).Text & """ runat=""server"" />")

    'create a validator control
    If validCheckBox.Checked Then
    sb.Append(" " & vbCrLf & CreateValidator(_item.Cells(1).Text))
    End If

    sb.Append("</td>" & chr(13)) '
    sb.Append(" </tr>" & chr(13)) ' close out the row
    End If

    Next
    sb.Append(" <tr>" & chr(13)) ' close out the row
    sb.Append(" <td colspan=""2""><asp:button id=""button1"" Text=""Validate Form"" runat=""Server"" /></td>" & vbCrLf)
    sb.Append(" </tr>" & chr(13)) ' close out the row
    sb.Append(" </table>" & chr(13))
    sb.Append(vbCrLf & "</form>")
    strOutput = sb.ToString()
    strOutput = System.Web.HttpUtility.HtmlEncode(strOutput)
    taResults.Value = strOutput
    pnlTextarea.Visible = True
    End Sub

    Private Sub InitializeComponent()

    End Sub

    End Class


    DISCLAIMER: The content provided in this article is not warranted or guaranteed by Developer Shed, Inc. The content provided is intended for entertainment and/or educational purposes in order to introduce to the reader key ideas, concepts, and/or product reviews. As such it is incumbent upon the reader to employ real-world tactics for security and implementation of best practices. We are not liable for any negative consequences that may result from implementing any information covered in our articles or tutorials. If this is a hardware review, it is not recommended to open and/or modify your hardware.

    More ASP.NET Code Articles
    More By aspfree

     

    IBM® developerWorks developerWorks - FREE Tools!


    IBM DB2 Deep Compression ROI Tool

    The IBM DB2 Deep Compression ROI tool is designed for DBA’s and IT management personnel to perform a clinical analysis of the cost savings gained from the Storage Optimization feature of DB2 9 for Linux, UNIX and Windows. The feature, also known as Deep Compression, compresses data that lies within a database by up to 80% at times.
    FREE! Go There Now!


    NEW! "ebook: Exploring IBM SOA Technology & Practice

    Learn field-tested SOA principles, methodology, technology and implementation from the global SOA market leader - in a new e-book by an IBM SOA expert. Written by IBM Certified SOA Solution Designer Bobby Woolf, "Exploring IBM SOA Technology & Practice" is the ultimate insider's guide to SOA - a PDF e-book packed cover to cover with IBM's specific advice on how to make your SOA implementation a success.
    FREE! Go There Now!


    NEW! A Layered approach to delivering security-rich Web applications

    As businesses grow increasingly dependent upon Web applications to provide services to customers, employees and partners, these complex applications become more difficult to secure. Although traditional security solutions protect Internet infrastructure layers, they do not guard against HTTP and HTML attacks. Many organizations that conduct security testing still deploy applications that allow attackers to manipulate their logic and wreak havoc on their business. To mitigate this risk, development and delivery teams must address Web application security throughout the lifecycle, addressing the many layers detailed in this paper.
    FREE! Go There Now!


    NEW! Build Web services with transport-level security using Rational Application Developer V7, Part 1: Build Web services and Web services clients

    Build secure Web services with transport-level security using IBM Rational Application Developer V7 and IBM WebSphere Application Server V6.1. Follow this three-part series for step-by-step instructions about how to develop Web services and clients, configure HTTP basic authentication, and configure HTTP over SSL (HTTPS). This first part of the series walks you through building a Web service for a simple calculator application. You generate and test two different types of Web services clients: a Java Platform, Enterprise Edition (Java EE) client and a stand-alone Java client. You also handle user-defined exceptions in Web services.
    FREE! Go There Now!


    NEW! Download a free trial of Lotus Quickr 8.0

    Visit IBM developerWorks to download a free trial version of Lotus Quickr 8.0, which enables collaboration by transforming the way everyday business content such as documents, rich media, photos, and video can be shared. Lotus Quickr makes it faster and easier to share content of all types (not just documents) within virtual teams. It is designed to make it easier to collaborate across organizational boundaries, while continuing to work within the context of familiar desktop applications.
    FREE! Go There Now!


    NEW! Evaluate WebSphere Extended Deployment Compute Grid V6.1

    Visit IBM developerWorks to download a free trial version of WebSphere Extended Deployment Compute Grid, which lets you schedule, execute, and monitor batch jobs. Because online transaction processing and batch jobs execute simultaneously on the same server resources, you can avoid costly duplication of resources. Compute Grid supports job types of Java transactional batch, compute-intensive and a new type called "native execution", which enables non-Java workloads to run on distributed end points.
    FREE! Go There Now!


    NEW! Run your first CICS application on a PC using TXSeries for Windows

    Learn the basics of the IBM Customer Information Control System (CICS). With a hands-on exercise, learn how to get your first CICS application up and running on your desktop using TXSeries V6.1 for Windows. The tutorial shows you how to download and install a free trial version of TXSeries V6.1.
    FREE! Go There Now!


    NEW! Section 508 of the U.S. Rehabilitation Act: Web accessibility compliance

    Because access to government information continues to be an area of concern for many U.S. citizens with disabilities, the U.S. government enacted Section 508 of the Rehabilitation Act in 2001 to ensure that government agencies create accessible Web content, enabling all citizens to access the information they need. A fully accessible Web site makes Web content accessible to all individuals, including those with disabilities, who may be accessing Web content via a variety of user agents. Common user agents include standard Web browsers, text-only browsers, assistive devices and mobile devices such as cell phones or personal digital assistants (PDAs).
    FREE! Go There Now!


    NEW! Webcast: Eclipse: Empowering the universal platform

    The Eclipse community is constantly working to extend Eclipse's functionality. In this webcast, learn about some of the most important and feature-rich projects under development. From multi-language support to plug-in development, tune in to see what Eclipse is capable of now.
    FREE! Go There Now!


    NEW! Webcast: Quickly provide customized, integrated user interfaces with Lotus Notes 8

    IBM Lotus Notes 8 provides a wide range of developers the ability to provide customized, integrated user interfaces via composite applications and via custom sidebar and toolbar plug-ins. This webcast provides you with tips and techniques to use with out-of-the-box capabilities of Lotus Notes 8, and survey how you can share useful components within your own company and within a larger community.
    FREE! Go There Now!



    All FREE IBM® developerWorks Tools!

    ASP.NET CODE ARTICLES

    - How to Use the ListBox Control in ASP.NET 2.0
    - How to Load XML Documents in ASP.NET 2.0
    - DataGrid Code
    - ASP.NET Guestbook
    - User Controls and Client Side Scripting
    - ASP.NET Programming with Microsoft's AS...
    - ASP.NET Basics (part 3): Hard Choices
    - ASP.NET Basics (part 2): Not My Type
    - ASP.NET Basics (part 1): Nothing But .Net
    - Directory Tree Browser
    - How to get the confirmation of Yes/No from a...
    - Complete example using custom errors and wri...
    - Paging Certain # records per page .NET style
    - General Methods of formatting and Subtractin...
    - .NET LinkButton web control





    © 2003-2009 by Developer Shed. All rights reserved. DS Cluster 1 Hosted by Hostway
    Stay green...Green IT