Contoh Form Pendaftaran ASP.NET
Contohnya ada Berikut ini :<%@ Page Title="" Language="VB" MasterPageFile="~/site.master" AutoEventWireup="false" CodeFile="daftar.aspx.vb" Inherits="register" %><asp:Content ID="Content1" ContentPlaceHolderID="head" Runat="Server"><script type="text/javascript"> var specialKeys = new Array(); specialKeys.push(8); //Backspace function IsNumeric(e) { var keyCode = e.which ? e.which : e.keyCode var ret = ((keyCode >= 48 && keyCode <= 57) || specialKeys.indexOf(keyCode) != -1); document.getElementById("error").style.display = ret ? "none" : "inline"; return ret; } </script></asp:Content><asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" Runat="Server"><div class="row"> <div class="col-lg-12"> <div class="panel panel-default"> <div class="panel-heading"> Daftar Keanggotaan </div> <div class="panel-body"> <div class="row"> <div class="col-lg-12"> <div class="form-group"> <label>Your ID</label> <asp:TextBox ID="tid" runat="server" CssClass="form-control" disabled></asp:TextBox> </div> <div class="form-group"> <label>Nama Kamu ?</label> <asp:TextBox ID="tnama" runat="server" CssClass="form-control" placeholder=" Masukan Nama Kamu !" autofocus></asp:TextBox> </div> <div class="form-group"> <label>Ussername</label> <asp:TextBox ID="tusername" runat="server" CssClass="form-control" placeholder=" Masukan Usser Name"></asp:TextBox> </div> <div class="form-group"> <label>Password</label> <asp:TextBox ID="tpassword" runat="server" CssClass="form-control" placeholder=" Buat Passsword"></asp:TextBox> </div> <div class="form-group"> <label>Email</label> <asp:TextBox ID="temail" runat="server" CssClass="form-control" placeholder=" Masukan Email Anda"></asp:TextBox> </div> <div class="form-group"> <label>No Tlp.</label> <asp:TextBox ID="thp" runat="server" CssClass="form-control" placeholder=" Masukan Nomor Handphone" onkeypress="return IsNumeric(event);" ondrop="return false;" onpaste="return false;"></asp:TextBox> <span id="error" style="color: Red; display: none">* Masukan Hanya Angka (0 - 9)</span> </div> <div class="form-group"> <label>Alamat</label> <asp:TextBox ID="talamat" runat="server" CssClass="form-control" placeholder=" Masukan Alamat" MaxLength="30"></asp:TextBox> <asp:RequiredFieldValidator ID="RequiredFieldValidator4" ErrorMessage=" *Masukan Alamat Anda" ForeColor="Red" ControlToValidate="talamat" runat="server" /> </div> <div class="form-group"> <asp:RequiredFieldValidator ID="RequiredFieldValidator5" runat="server" ControlToValidate="tnama" ErrorMessage="* Nama Tidak Boleh Kosong" ForeColor="Red" /> <asp:RequiredFieldValidator ID="RequiredFieldValidator3" runat="server" ControlToValidate="thp" ErrorMessage="* Nomor HP Tidak Boleh Kosong! " ForeColor="Red" /> <asp:RegularExpressionValidator ID="RegularExpressionValidator2" runat="server" ErrorMessage=" * Ussername Tidak Boleh Pake Spasi" ControlToValidate="tusername" ValidationExpression="[^\s]+" /> <asp:RequiredFieldValidator ID="vry" runat="server" ControlToValidate="tusername" ErrorMessage="* Ussername Tidak Boleh Kosong! " ForeColor="Red" /> <asp:RegularExpressionValidator ID="RegExp1" runat="server" ErrorMessage="* Masukan Ussername Minimal 6 Digit Maksimal 10 Digit"ControlToValidate="tusername" ValidationExpression="^[a-zA-Z]{6,10}$" /> <asp:RequiredFieldValidator ID="RequiredFieldValidator1" runat="server" ControlToValidate="tusername" ErrorMessage="* Password Tidak Boleh Kosong! " ForeColor="Red" /> <asp:RegularExpressionValidator ID="RegularExpressionValidator3" runat="server" ErrorMessage=" *Password Panjang 6-10 Digit Dan Tidak Boleh Ada Angka"ControlToValidate="tpassword" ValidationExpression="^[a-zA-Z0-9'@&#.\s]{6,10}$"/> <asp:RequiredFieldValidator ID="RequiredFieldValidator2" ErrorMessage="* Email Harus Di Isi" Display="Dynamic" ForeColor="Red" ControlToValidate="temail" runat="server" /> <asp:RegularExpressionValidator ID="RegularExpressionValidator1" runat="server" Display="Dynamic" ValidationExpression="\w+([-+.']\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*" ControlToValidate="temail" ForeColor="Red" ErrorMessage=" *Email Tidak Valid/Salah" /> </div> <asp:Button ID="btndaftar" runat="server" Text="Daftar" CssClass ="btn btn-lg btn-success btn-block" /> </div> </div> </div> </div> </div> </div> </asp:Content>Berikut ini Koding Belakangnya :
Imports System.Data
Imports System.Configuration
Imports System.Data.SqlClient
Partial Class register
Inherits System.Web.UI.Page
Private Function CpuId() As String
' On Error Resume Next
Dim computer As String = "."
Dim wmi As Object = GetObject("winmgmts:" & _
"{impersonationLevel=impersonate}!\\" & _
computer & "\root\cimv2")
Dim processors As Object = wmi.ExecQuery("Select * from Win32_Processor")
Dim cpu_ids As String = ""
For Each cpu As Object In processors
cpu_ids = cpu_ids & ", " & cpu.ProcessorId
Next cpu
If cpu_ids.Length > 0 Then cpu_ids = cpu_ids.Substring(2)
'BFEBFBFF00000F47
Return cpu_ids
End Function
Sub simpaneditserver()
Dim userId As String = tid.Text.Trim
Call Koneksi()
'CONN.Open()
CMD = New SqlCommand("SELECT * from TBLJumlahPakai where id='" & tid.Text.Trim & "' and ussername='" & tusername.Text.Trim & "' and email='" & temail.Text.Trim & "' and nope='" & thp.Text.Trim & "'", CONN)
RD = CMD.ExecuteReader
RD.Read()
If Not RD.HasRows Then
Using con As New SqlConnection(connStr)
Using cmde As New SqlCommand("INSERT INTO TBLJumlahPakai (id,nama,ussername,password,email,nope,alamat,digunakan,batas,reg,status) VALUES (@id,@nama, @ussername,@password, @email, @nope, @alamat,@digunakan,@batas,@reg,@status)")
cmde.Parameters.AddWithValue("id", tid.Text)
cmde.Parameters.AddWithValue("nama", tnama.Text.Trim)
cmde.Parameters.AddWithValue("ussername", tusername.Text.Trim)
cmde.Parameters.AddWithValue("password", tpassword.Text.Trim)
cmde.Parameters.AddWithValue("email", temail.Text.Trim)
cmde.Parameters.AddWithValue("nope", thp.Text.Trim)
cmde.Parameters.AddWithValue("alamat", talamat.Text.Trim)
cmde.Parameters.AddWithValue("digunakan", "0")
cmde.Parameters.AddWithValue("batas", "0")
cmde.Parameters.AddWithValue("reg", DateTime.Now.ToString("MMMM-dd-yyyy"))
cmde.Parameters.AddWithValue("status", "Not Verified")
cmde.Connection = con
con.Open()
userId = Convert.ToInt32(cmde.ExecuteScalar())
con.Close()
End Using
End Using
Dim message As String = String.Empty
Select Case userId
Case -1
message = "Pendaftaran Berhasil"
Exit Select
Case Else
message = "Berhasil !!! \nPendaftaran Berhasil.\nYour ID: " + tid.Text.Trim()
Response.Redirect("~/berhasil.aspx")
Exit Select
End Select
ClientScript.RegisterStartupScript([GetType](), "alert", (Convert.ToString("alert('") & message) + "');", True)
Else
Dim message As String = String.Empty
Select Case userId
Case -1
message = "Gagal ! \nMungkin ID,Ussername,Email Dan Nomor HP Anda Sudah Terdaftar Sebelumnya"
Exit Select
Case Else
message = "Gagal ! \nMungkin ID,Ussername,Email Dan Nomor HP Anda Sudah Terdaftar Sebelumnya,Silakan Login !.\nYour ID: " + tid.Text.Trim()
Exit Select
Response.Redirect("~/login.aspx")
End Select
ClientScript.RegisterStartupScript([GetType](), "alert", (Convert.ToString("alert('") & message) + "');", True)
End If
End Sub
Protected Sub Page_Load(sender As Object, e As System.EventArgs) Handles Me.Load
tid.Text = CpuId()
End Sub
Protected Sub btndaftar_Click(sender As Object, e As System.EventArgs) Handles btndaftar.Click
Call simpaneditserver()
End Sub
End Class
0 KOMENTAR