<%@ Page Language="C#" MasterPageFile="~/MainMasterPage.master" AutoEventWireup="true" CodeFile="StudentRegistration.aspx.cs" Inherits="StudentRegistration" Title="Untitled Page" %> <asp:Content ID="Content1" ContentPlaceHolderID="ContentBody" runat="Server"> <center> <form id="form1" runat="server"> <table> <tr> <td colspan="2"> Registration Form </td> </tr> <tr> <td> First Name </td> <td> <asp:TextBox ID="txtFName" runat="server" Width="150"></asp:TextBox> <asp:RequiredFieldValidator ID="rfvFName" runat="server" ControlToValidate="txtFName" ErrorMessage="*"></asp:RequiredFieldValidator> </td> </tr> <tr> <td> Last Name </td> <td> <asp:TextBox ID="txtLName" runat="server" Width="150"></asp:TextBox> <asp:RequiredFieldValidator ID="rfvLName" runat="server" ControlToValidate="txtLName" ErrorMessage="*"></asp:RequiredFieldValidator> </td> </tr> <tr> <td> Contact No </td> <td> <asp:TextBox ID="txtContactNo" runat="server" Width="150"></asp:TextBox> <asp:RequiredFieldValidator ID="rfvContactNo" runat="server" ControlToValidate="txtContactNo" ErrorMessage="*"></asp:RequiredFieldValidator> </td> </tr> <tr> <td> Email-Id </td> <td> <asp:TextBox ID="txtEmail" runat="server" Width="150"></asp:TextBox> <asp:RequiredFieldValidator ID="RequiredFieldValidator1" runat="server" ControlToValidate="txtContactNo" ErrorMessage="*"></asp:RequiredFieldValidator> </td> </tr> <tr> <td> Address </td> <td> <asp:TextBox ID="txtAddress" runat="server" Width="150" TextMode="MultiLine"></asp:TextBox> <asp:RequiredFieldValidator ID="rfvAddress" runat="server" ControlToValidate="txtAddress" ErrorMessage="*"></asp:RequiredFieldValidator> </td> </tr> <tr> <td> Date Of Birth </td> <td> <asp:TextBox ID="txtDOB" runat="server" Width="150"></asp:TextBox> <asp:RequiredFieldValidator ID="rfvDOB" runat="server" ControlToValidate="txtDOB" ErrorMessage="*"></asp:RequiredFieldValidator> </td> </tr> <tr> <td> User Name </td> <td> <asp:TextBox ID="txtUserName" runat="server" Width="150"></asp:TextBox> <asp:RequiredFieldValidator ID="efvUserName" runat="server" ControlToValidate="txtUserName" ErrorMessage="*"></asp:RequiredFieldValidator> </td> </tr> <tr> <td> Password </td> <td> <asp:TextBox ID="txtPassword" runat="server" Width="150" TextMode="Password"></asp:TextBox> <asp:RequiredFieldValidator ID="rfvpassword" runat="server" ControlToValidate="txtPassword" ErrorMessage="*"></asp:RequiredFieldValidator> </td> </tr> <tr> <td> Role </td> <td> <asp:RadioButtonList ID="RadioButtonList1" runat="server" RepeatDirection="Horizontal"> <asp:ListItem>Student</asp:ListItem> <asp:ListItem>Teacher</asp:ListItem> </asp:RadioButtonList> <asp:RequiredFieldValidator ID="RequiredFieldValidator4" runat="server" ErrorMessage="Select role" ControlToValidate="RadioButtonList1"></asp:RequiredFieldValidator> </td> </tr> <tr> <td> Security Question </td> <td> <asp:TextBox ID="txtSecQues" runat="server" Width="150"></asp:TextBox> <asp:RequiredFieldValidator ID="rfvsecques" runat="server" ControlToValidate="txtSecQues" ErrorMessage="*"></asp:RequiredFieldValidator> </td> </tr> <tr> <td> Security Answer </td> <td> <asp:TextBox ID="txtSecAns" runat="server" Width="150"></asp:TextBox> <asp:RequiredFieldValidator ID="rfvSecAns" runat="server" ControlToValidate="txtSecAns" ErrorMessage="*"></asp:RequiredFieldValidator> </td> </tr> <tr> <td colspan="2"> <asp:Button ID="btnSubmit" runat="server" Text="Submit" OnClick="btnSubmit_Click" /> </td> </tr> </table> <asp:Label ID="lblMsg" runat="server" Text=""></asp:Label> </form> </center> </asp:Content>
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; public partial class StudentRegistration : System.Web.UI.Page { protected void Page_Load(object sender, EventArgs e) { } static int i; static string strMsg; BALQuestions insobj = new BALQuestions(); public void InsertStudentDetails() { DateTime DateConverted; bool IsValid = DateTime.TryParse(txtDOB.Text.Trim(), out DateConverted); if (IsValid == false) { return; //value in TextBox2 is not valid } insobj.FName = txtFName.Text; insobj.LName = txtLName.Text; insobj.ContactNo = txtContactNo.Text; insobj.Email = txtEmail.Text; insobj.Address = txtAddress.Text; insobj.DOB = DateConverted.ToString("dd-MM-yyyy"); insobj.UserName = txtUserName.Text; insobj.Password = txtPassword.Text; insobj.role = RadioButtonList1.SelectedValue; insobj.SecQues = txtSecQues.Text; insobj.SecAns = txtSecAns.Text; i = insobj.InsertStudent(out strMsg); } protected void btnSubmit_Click(object sender, EventArgs e) { try { InsertStudentDetails(); if (i > 1) { ClearData(); lblMsg.Text = strMsg; } else lblMsg.Text = strMsg; } catch (Exception ex) { lblMsg.Text = ex.Message; } } public void ClearData() { txtFName.Text= txtLName.Text = txtContactNo.Text = txtAddress.Text= txtDOB.Text=""; txtUserName.Text = txtPassword.Text = txtSecQues.Text = txtSecAns.Text = ""; } }
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)