Quantcast
Channel: All About ASP.NET and ASP.NET Core 2 Hosting BLOG - asp.net hosting
Viewing all articles
Browse latest Browse all 70

ASP.NET 4.5.1 Hosting - ASPHostPortal.com :: How to Create a Sign Up/Registration Page in ASP.NET

$
0
0

Here is the simple step to create a sign up/registration page in ASP.NET. Lets check this out :
1. Open the Microsoft Visual Studio
2. Select one New Asp.Net Web application
3. Open the Design Default.aspx page
4. Drag and Drop one DropDown list and button from the Tool box.
5. Add one new item( i.e., New Registration Page) for the Drop down list
6. Procedure for adding items : Right click on the DropDown List and select properties and select items and add NewRegistration in Text Field.
7. Change the properties of the Dropdown list
a.Kept AutopostBack = True;
b.select the SelectedIndexChanged Event for that..
8. Open the code page that is Default.aspx.cs and and create a method in SelectedIndexChanged event of dropdownlist

using System; 
using System.Collections; 
using System.Configuration; 
using System.Data; 
using System.Linq; 
using System.Web; 
using System.Web.Security; 
using System.Web.UI; 
using System.Web.UI.HtmlControls; 
using System.Web.UI.WebControls; 
using System.Web.UI.WebControls.WebParts; 
using System.Xml.Linq; 
using System.Data.SqlClient; 
 
public partial class Dynamic_controls : System.Web.UI.Page 

    SqlConnection con; 
    SqlCommand com; 
  protected void Page_Load(object sender, EventArgs e) 
    {        
        
    } 
protected void ddlist_SelectedIndexChanged(object sender, EventArgs e) 
    { 
        Createnewaccount();  
    } 

9. Create new methods for Different controls by using the main method(i.e., Createnewaccount)

private void Createnewaccount ()
         {
             CreateDynamicTextBoxes ();
             CreateDynamicTextBoxes1 ();
             CreateDynamicCheckBoxes ();
             CreateDynamicCheckBoxes1 ();
             CreateDynamicRadioButtons1 ();
             BindDropDownLists ();
         }

10. Create all types of dynamic controls

 protected void CreateDynamicTextBoxes ( )
        {
           
            int c = 1 ;
            TextBox [ ] textBoxArr = new TextBox [ c ] ;/ / array of textboxes
            for (int i = 0 ; i < c ; i + + )
            {
                 
                textBoxArr [ i ] = new TextBox ( ) ;
                textBoxArr [ i ] . ID = " txtBox " + i.ToString ( ) ;
                PH_Name.Controls.Add ( textBoxArr [ i ] ) ;
                RequiredFieldValidator reqfldVal = new RequiredFieldValidator ( ) ;
                reqfldVal.ID = " RequiredValidator " + i ;
                reqfldVal.ControlToValidate = " txtBox " + i ;
                reqfldVal.ErrorMessage = " Not Empty " ;
                reqfldVal.SetFocusOnError = true ;
                PH_Name.Controls.Add ( reqfldVal ) ;
            }
        }
        protected void CreateDynamicTextBoxes1 ( )
        {
            int c = 1 ;
            TextBox [ ] textBoxArr1 = new TextBox [ c ] ;/ / array of textboxes
            for (int i = 0 ; i < c ; i + + )
            {
      
                textBoxArr1 [ i ] = new TextBox ( ) ;
                textBoxArr1 [ i ] . ID = " txtBox1 " + i.ToString ( ) ;
                PH_pwd.Controls.Add ( textBoxArr1 [ i ] ) ;
                RequiredFieldValidator reqfldVal1 = new RequiredFieldValidator ( ) ;
                reqfldVal1.ID = " RequiredValidator1 " + i ;
                reqfldVal1.ControlToValidate = " txtBox1 " + i ;
                reqfldVal1.ErrorMessage = " Not Empty " ;
                reqfldVal1.SetFocusOnError = true ;
                PH_pwd.Controls.Add ( reqfldVal1 ) ;
                 
            }
        }
        private void BindDropDownLists ( )
        {
            SqlDataSource sqlDS = new SqlDataSource ( ) ;
            sqlDS.ConnectionString = ConfigurationManager.ConnectionStrings [ " SAMPLE_2 " ] . ToString ( ) ;
            sqlDS.SelectCommand = " Select CountryID , COUNTRY_NAME from countrynames " ;
            PH_country.Controls.Add ( sqlDS ) ;
            DropDownList ddl = new DropDownList ( ) ;
            ddl.ID = " ddlrank " ;
            ddl.DataSource = sqlDS ;
            ddl.DataTextField = " COUNTRY_NAME " ;
            ddl.DataValueField = " CountryID " ;
            PH_country.Controls.Add ( ddI ) ;
            foreach ( Control ctl in PH_country.Controls )
            {
                if ( ctl is DropDownList )
                {
                    ( ctl as DropDownList ) . DataBind ( ) ;
                }
            }
        }
        protected void CreateDynamicCheckBoxes ( )
        {
                   
                CheckBox chk ;
                chk = new CheckBox ( ) ;
                chk.ID = " chkhobbies " ;
                chk.Text = " savings " ;
                chk.AutoPostBack = false ;
                PH_trans.Controls.Add ( chk ) ;
             
        }
        protected void CreateDynamicCheckBoxes1 ( )
        {
           
            int c = 1 ;
            CheckBox [ ] chk = new CheckBox [ c ] ;
            for (int i = 0 ; i < c ; i + + )
            {
                chk [ i ] = new CheckBox ( ) ;
                chk [ i ] . ID = " chkhobbies1 " + i.ToString ( ) ;
                chk [ i ] . Text = " Current" ;
                chk [ i ] . AutoPostBack = false ;
                PH_trans.Controls.Add ( chk [ i ] ) ;
            }
        }
        protected void CreateDynamicRadioButtons ( )
        {
                Male = new RadioButton RadioButton ( ) ;
                Female = new RadioButton RadioButton ( ) ;
                male = new RadioButton ( ) ;
                female = new RadioButton ( ) ;
                male.Text = " Male " ;
                female.Text = " Female " ;
                male.Checked = false ;
                female.Checked = false ;
                male.GroupName = " unknown " ;
                female.GroupName = " unknown " ;
                male.ID = " malegender " ;
                female.ID = " unknown " ;
                male.AutoPostBack = false ;
                female.AutoPostBack = false ;
                PH_gender.Controls.Add ( male ) ;
                PH_gender.Controls.Add (female ) ;
        }
        protected void CreateDynamicRadioButtons1 ( )
        {
            RadioButtonList radio = new RadioButtonList ( ) ;
            radio.ID = " rblRow " ;
            radio.Items.Add ( new ListItem ( " Male " ) ) ;
            radio.Items.Add ( new ListItem ( " Female " ) ) ;
            PH_gender.Controls.Add ( radio ) ;
             
        }
        protected void CreateDynamicPanel ( )
        {
           
            int c = 1 ;
            TextPanel panel = new Panel ( ) ;
            for (int i = 0 ; i < c ; i + + )
            {
                TextPanel.ID = " txtPanel " + i.ToString ( ) ;
                PlaceHolder1.Controls.Add ( TextPanel ) ;
            }
        }

11. Add the following code to store the data in database

protected void btn_submit_Click ( object sender , EventArgs e )
        {
            for (int i = 0 ; i < 1 ; i + + )
            {
                 
                txtvalue string = " txtBox " + i.ToString ( ) ;
                txtvalue1 string = " txtBox1 " + i.ToString ( ) ;
                ddlvalue string = " ddlrank " ;
                chkvalue string = " chkhobbies " ;
                chkvalue1 string = " chkhobbies1 " + i.ToString ( ) ;
                rbvalue string = " rblRow " ;
                 
                TextBox txt = ( TextBox ) PlaceHolder1.FindControl ( txtvalue ) ;
                TextBox txt1 = ( TextBox ) PlaceHolder1.FindControl ( txtvalue1 ) ;
                DropDownList Dddl = ( DropDownList ) PlaceHolder1.FindControl ( ddlvalue ) ;
                CheckBox Dchk = ( CheckBox ) PlaceHolder1.FindControl ( chkvalue ) ;
                CheckBox Dchk1 = ( CheckBox ) PlaceHolder1.FindControl ( chkvalue1 ) ;
                RadioButtonList Drd = ( RadioButtonList ) PlaceHolder1.FindControl ( rbvalue ) ;
                if ( txt ! = null )
                {
                    try
                    {
                        string strText = txt.Text ;
                        strText1 string = txt1.Text ;
                        strddl string = Dddl.SelectedItem.Text ;
                        strchk string = Dchk.Text ;
                        strchk1 string = Dchk1.Text ;
                        strrdb string = Drd.Text ;
                        / / Store value in database textbox Cell
                        con = new SqlConnection ( ConfigurationManager.ConnectionStrings [ " SAMPLE_2 " ] . ToString ( ) ) ;
                        con.Open ( ) ;
                        com = new SqlCommand ( " insert into Dynamic_Form ( UserName , LastName , DropdownlistValue , Chksavings , Chkcurrent , Radiovalue ) values ​​( ' " + strText + " ' , ' " + strText1 + " ' , ' " + strddl + " ' , ' " strchk + + " ' , ' " + strchk1 + " ' , ' " + strrdb + " ' ) " , con ) ;
                        com.ExecuteNonQuery ( ) ;
                        con.Close ( ) ;
                        lbl_error.Text = " Account Successfully Created " ;
                         
                    }
                    catch ( Exception ex )
                    {
                        throw ex ;
                        / / lbl_error.Text = " There is a problem while creating Account " ;
                         
                    }
                }
            }
        }

Now, run your program and see the result :


Viewing all articles
Browse latest Browse all 70

Trending Articles