Validation Summary Not Displaying (C# ASP.NET 4.5) - c#

I have a an ASP.NET web form that needs to valid user input. However, upon entering invalid-user input the validation summary is not displaying. The weird thing was that it was working for a period of time and then now it doesn't show at all. Here is my code.
<%# Page Language="C#" AutoEventWireup="true" CodeFile="Registration.aspx.cs" Inherits="Registration" %>
<!DOCTYPE html>
<html>
<head>
<title>Coding Club Registration</title>
<link href="StyleSheet.css" rel="stylesheet" type="text/css" />
</head>
<body>
<h1>Coding Club Registration Form</h1>
<form runat="server" defaultbutton="Submit">
<div>
<asp:Label ID="NameLabel" runat="server" Text="Your Name:" AssociatedControlID="NameTextBox" AccessKey="N"></asp:Label>
<asp:TextBox ID="NameTextBox" runat="server" Columns="30" MaxLength="30"></asp:TextBox>
<asp:RequiredFieldValidator ID="RequiredFieldValidator2" runat="server" ControlToValidate="NameTextBox" CssClass="error" ErrorMessage="Name Required"><span>*</span></asp:RequiredFieldValidator>
<br /><br />
<asp:Label ID="EmailLabel" runat="server" Text="Your Email:" AssociatedControlID="EmailTextBox" AccessKey="N"></asp:Label>
<asp:TextBox ID="EmailTextBox" runat="server" Columns="30" MaxLength="30"></asp:TextBox>
<asp:RequiredFieldValidator ID="RequiredFieldValidator1" runat="server" ControlToValidate="EmailTextBox" CssClass="error" Display="Dynamic" ErrorMessage="Email Required"><span>*</span></asp:RequiredFieldValidator>
<asp:RegularExpressionValidator ID="RegularExpressionValidator1" runat="server" ControlToValidate="EmailTextBox" CssClass="error" Display="Dynamic" ErrorMessage="Invalid Email" ValidationExpression="\w+([-+.']\w+)*#\w+([-.]\w+)*\.\w+([-.]\w+)*">*</asp:RegularExpressionValidator>
<br /><br />
<asp:Label ID="PhoneLabel" runat="server" Text="Your Phone:" AssociatedControlID="PhoneTextBox" AccessKey="N"></asp:Label>
<asp:TextBox ID="PhoneTextBox" runat="server" Columns="30" MaxLength="30"></asp:TextBox>
<asp:RequiredFieldValidator ID="RequiredFieldValidator3" runat="server" ControlToValidate="PhoneTextBox" CssClass="error" Display="Dynamic" ErrorMessage="Phone Required"><span>*</span></asp:RequiredFieldValidator>
<asp:RegularExpressionValidator ID="RegularExpressionValidator2" runat="server" ControlToValidate="PhoneTextBox" CssClass="error" Display="Dynamic" ErrorMessage="Invalid Phone" ValidationExpression="((\(\d{3}\) ?)|(\d{3}-))?\d{3}-\d{4}">*</asp:RegularExpressionValidator>
<br /><br />
<asp:Button ID="Submit" runat="server" Text="Submit Form" AccessKey="S" onclick="SubmitButton_Click" />
<asp:Button ID="Clear" runat="server" Text="Clear Form" AccessKey="C" onclick="ClearButton_Click" CausesValidation="False" />
<br /><br />
<div class="container">
<asp:Label ID="Result" runat="server" Text="" Visible="false"></asp:Label>
</div>
</div>
<asp:ValidationSummary ID="Errors" runat="server" ForeColor="Red" />
</form>
</body>
</html>
protected void SubmitButton_Click(object sender, EventArgs e)
{
if (Page.IsValid)
{
// Add form results to result label
string newText = "<h3>The Information Entered</h3>";
newText += "<p>Name: " + NameTextBox.Text + "</p>";
newText += "<p>Email: " + EmailTextBox.Text + "</p>";
newText += "<p>Phone: " + PhoneTextBox.Text + "</p>";
Result.Text = newText;
// Set result lable visibility to true
Result.Visible = true;
}
}
protected void ClearButton_Click(object sender, EventArgs e)
{
// Clear form fields
NameTextBox.Text = "";
EmailTextBox.Text = "";
PhoneTextBox.Text = "";
// Remove result visibility
Result.Visible = false;
// Errors.Visible = false;
}
}
Any help would be appreciated!

Related

How to make the information in a dropdownlist change

So i want to make a drop down list that displays new information if you select different radio buttons.
And im struggling.For Example if radio button 1 is selected the information in dropbox must change to popcorn and sweets.
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
<style type="text/css">
.auto-style1 {
margin-left: 18px;
}
</style>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:RadioButton ID="RadioButton1" runat="server" OnCheckedChanged="RadioButton1_CheckedChanged" Text="Day" />
</div>
<asp:RadioButton ID="RadioButton2" runat="server" Text="Night" />
<br />
<br />
<asp:DropDownList ID="DropDownList1" runat="server">
<asp:ListItem>Cream Soda</asp:ListItem>
<asp:ListItem>coke</asp:ListItem>
</asp:DropDownList>
<br />
<br />
<asp:Label ID="Label1" runat="server" Text="Name"></asp:Label>
<asp:TextBox ID="TextBox1" runat="server" CssClass="auto-style1" Width="139px"></asp:TextBox>
<br />
<asp:Label ID="Label2" runat="server" Text="Seat No:"></asp:Label>
<asp:TextBox ID="TextBox2" runat="server" Width="140px"></asp:TextBox>
<br />
<br />
<asp:Button ID="Button1" runat="server" Height="20px" Text="Add Choice" />
<br />
<asp:Label ID="Label3" runat="server"></asp:Label>
</form>
</body>
</html>
You must define autopostback="true" on the RadioButton, and then you need to handle the selected value in the codebehind, and re-fill the drop-down with a new item-list.
Page-Cycle will be like this
Page_Load
RadioButton2_Changed
Page_LoadComplete
So make sure you either set the new content in RadioButton2_Changed, or in Page_LoadComplete. If you try to do it in Page_Load, you'll have the old value of radiobutton, and that will not work well ...
You can try the following steps to show the correspond information when you click the radio button.
First, you need to change your html file into the following:
<body>
<form id="form1" runat="server">
<div>
<asp:RadioButton ID="RadioButton1" runat="server" OnCheckedChanged="RadioButton1_CheckedChanged" Text="Day" GroupName="Ra" AutoPostBack="true" />
</div>
<asp:RadioButton ID="RadioButton2" runat="server" Text="Night" OnCheckedChanged="RadioButton2_CheckedChanged" GroupName="Ra" AutoPostBack="true"/>
<br />
<br />
<asp:DropDownList ID="DropDownList1" runat="server">
</asp:DropDownList>
<br />
<br />
<asp:Label ID="Label1" runat="server" Text="Name"></asp:Label>
<asp:TextBox ID="TextBox1" runat="server" CssClass="auto-style1" Width="139px"></asp:TextBox>
<br />
<asp:Label ID="Label2" runat="server" Text="Seat No:"></asp:Label>
<asp:TextBox ID="TextBox2" runat="server" Width="140px"></asp:TextBox>
<br />
<br />
<asp:Button ID="Button1" runat="server" Height="20px" Text="Add Choice" />
<br />
<asp:Label ID="Label3" runat="server"></asp:Label>
</form>
</body>
Second, you need to call the RadioButton1_CheckedChanged event and RadioButton2_CheckedChanged event to to add the listitem.
ListItem list1 = new ListItem("popcorn");
ListItem list2 = new ListItem("sweets");
ListItem list3 = new ListItem("Cream Soda");
ListItem list4 = new ListItem("coke");
protected void RadioButton1_CheckedChanged(object sender, EventArgs e)
{
if(RadioButton1.Checked==true)
{
if (!DropDownList1.Items.Contains(list1) && !DropDownList1.Items.Contains(list2))
{
DropDownList1.Items.Clear();
DropDownList1.Items.Add(list1);
DropDownList1.Items.Add(list2);
}
}
}
protected void RadioButton2_CheckedChanged(object sender, EventArgs e)
{
if (RadioButton2.Checked == true)
{
if (!DropDownList1.Items.Contains(list3) && !DropDownList1.Items.Contains(list4))
{
DropDownList1.Items.Clear();
DropDownList1.Items.Add(list3);
DropDownList1.Items.Add(list4);
}
}
}
Result:

null reference exception on page redirect

I'm getting a null reference exception on singleKingButton.Checked = true; in the page load event. If I comment it out then I still get one on the next line setting the date. The odd thing is the page loads fine it's when I hit the submit button that I get the error. Thanks in advance!
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
namespace garrettPenfieldUnit4
{
public partial class Default : System.Web.UI.Page
{
Reservation newReservation = new Reservation();
//Load events, automatically inserts todays date and selects the single king radio button
protected void Page_Load(object sender, EventArgs e)
{
UnobtrusiveValidationMode = System.Web.UI.UnobtrusiveValidationMode.None;
singleKingButton.Checked = true;
arrivalDateBox.Text = DateTime.Today.ToShortDateString();
}
//When submit button is clicked show the two confirmation labels.
protected void submitButton_Click(object sender, EventArgs e)
{
newReservation.ArrivalDate = Convert.ToDateTime(arrivalDateBox.Text);
newReservation.DepartureDate = Convert.ToDateTime(departureDateBox.Text);
newReservation.NoOfPeople = peopleDropDown.SelectedIndex;
newReservation.SpecialRequests = specialRequestsBox.Text;
newReservation.FirstName = firstNameBox.Text;
newReservation.LastName = lastNameBox.Text;
newReservation.Email = addressBox.Text;
newReservation.Phone = telephoneNumberBox.Text;
newReservation.PreferredMethod = contactDropDown.SelectedIndex.ToString();
if (singleKingButton.Checked)
{
newReservation.BedType = "Single King";
}
if (twoQueensButton.Checked)
{
newReservation.BedType = "Two Queens";
}
if (singleQueenButton.Checked)
{
newReservation.BedType = "Single Queen";
}
Session["Reservation"] = newReservation;
Response.Redirect("~/ConfirmationPage.aspx");
}
//When the clear button is clicked clear the form and reset fields to their default values
protected void clearButton_Click(object sender, EventArgs e)
{
arrivalDateBox.Text = DateTime.Today.ToShortDateString();
departureDateBox.Text = String.Empty;
peopleDropDown.SelectedIndex = 0;
singleKingButton.Checked = true;
twoQueensButton.Checked = false;
singleQueenButton.Checked = false;
specialRequestsBox.Text = String.Empty;
firstNameBox.Text = String.Empty;
lastNameBox.Text = String.Empty;
addressBox.Text = String.Empty;
telephoneNumberBox.Text = String.Empty;
contactDropDown.SelectedIndex = 0;
}
}
}
<%# Page Language="C#" AutoEventWireup="true" CodeBehind="Default.aspx.cs" Inherits="garrettPenfieldUnit4.Default" %>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title>Royal Inn and Suites</title>
<link href="Content/bootstrap.css" rel="stylesheet" />
<link href="Content/Main.css" rel="stylesheet" />
<script src="Scripts/jquery-1.9.1.min.js"></script>
<script src="Scripts/bootstrap.min.js"></script>
</head>
<body>
<form id="form1" runat="server" defaultbutton="submitButton" defaultfocus="arrivalDateBox">
<div class="container">
<div id="page-header">
<h1 style="color: blue;">Royal Inn and Suites</h1>
<p style="color: red; font-style: italic;">
Where you're always treated like royalty
</div>
<h3 style="color: blue;">Reservation Request</h3>
<asp:ValidationSummary ID="ValidationSummary1" runat="server" ForeColor="Red" />
</div>
<div id="form-group">
<h4>Request Data</h4>
<div>
Arrival Date<asp:RequiredFieldValidator ID="arrivalDateBoxValidator" runat="server" ErrorMessage="Arrival date is required"
ControlToValidate="arrivalDateBox" ForeColor="Red" Display="Dynamic">*</asp:RequiredFieldValidator>
<asp:CompareValidator ID="arrivalDateValidator" runat="server" ErrorMessage="Arrival date must be before departure date."
ControlToValidate="arrivalDateBox" ControlToCompare="departureDateBox" Display="Dynamic"
Operator="DataTypeCheck" Type="Date" ForeColor="red">*</asp:CompareValidator>
</div>
<div>
<asp:TextBox ID="arrivalDateBox" runat="server" CssClass="form-control"></asp:TextBox>
</div>
<div>Departure Date</div>
<div>
<asp:TextBox ID="departureDateBox" runat="server" CssClass="form-control"></asp:TextBox>
<asp:RequiredFieldValidator ID="departureDateBoxValidator" runat="server" ErrorMessage="Departure date is required"
ControlToValidate="departureDateBox" ForeColor="Red" Display="Dynamic">*</asp:RequiredFieldValidator>
<asp:CompareValidator ID="departureDateCompareValidator" runat="server" ErrorMessage="Departure date must be after arrival date"
ControlToValidate="departureDateBox" ForeColor="Red" ControlToCompare="arrivalDateBox" Display="Dynamic" Operator="GreaterThan"
Type="Date">*</asp:CompareValidator>
</div>
<div>Number of People</div>
<div>
<asp:DropDownList ID="peopleDropDown" runat="server" CssClass="form-control">
<asp:ListItem>1</asp:ListItem>
<asp:ListItem>2</asp:ListItem>
<asp:ListItem>3</asp:ListItem>
<asp:ListItem>4</asp:ListItem>
</asp:DropDownList>
</div>
<div>
<div>
Bed Type
<asp:RadioButton ID="singleKingButton" runat="server" Text="King" GroupName="bedType" />
<asp:RadioButton ID="twoQueensButton" runat="server" Text="Two Queens" GroupName="bedType" />
<asp:RadioButton ID="singleQueenButton" runat="server" Text="Single Queen" GroupName="bedType" />
</div>
</div>
<h3>Special Requests</h3>
<div>
<asp:TextBox ID="specialRequestsBox" runat="server" TextMode="MultiLine" CssClass="form-control"></asp:TextBox>
</div>
<h3>Contact Information</h3>
<div>First Name</div>
<asp:TextBox ID="firstNameBox" runat="server" CssClass="form-control"></asp:TextBox>
<asp:RequiredFieldValidator ID="firstNameBoxValidator" runat="server" ErrorMessage="First name is required"
ControlToValidate="firstNameBox" ForeColor="Red">*</asp:RequiredFieldValidator>
<div>Last Name</div>
<asp:TextBox ID="lastNameBox" runat="server" CssClass="form-control"></asp:TextBox>
<asp:RequiredFieldValidator ID="lastNameBoxValidator" runat="server" ErrorMessage="Last name is required"
ControlToValidate="lastNameBox" ForeColor="Red">*</asp:RequiredFieldValidator>
<div>E-mail Address</div>
<asp:TextBox ID="addressBox" runat="server" CssClass="form-control"></asp:TextBox>
<asp:RequiredFieldValidator ID="addressBoxValidator" runat="server" ErrorMessage="Email address is required"
ControlToValidate="addressBox" ForeColor="Red" Display="Dynamic">*</asp:RequiredFieldValidator>
<asp:RegularExpressionValidator ID="addressBoxExpressionValidator1" runat="server" ErrorMessage="Invalid Email"
ControlToValidate="addressBox" ForeColor="Red" Display="Dynamic" ValidationExpression="\w+([-+.']\w+)*#\w+([-.]\w+)*\.\w+([-.]\w+)*">*</asp:RegularExpressionValidator>
<div>Telephone Number</div>
<asp:TextBox ID="telephoneNumberBox" runat="server" CssClass="form-control"></asp:TextBox>
<asp:RequiredFieldValidator ID="telephoneNumberBoxValidator" runat="server" ErrorMessage="Telephone Number is required"
ControlToValidate="telephoneNumberBox" ForeColor="Red" Display="Dynamic">*</asp:RequiredFieldValidator>
<asp:RegularExpressionValidator ID="telephoneExpressionValidator" runat="server"
ErrorMessage="Invalid phone number" ControlToValidate="telephoneNumberBox" ForeColor="red" Display="Dynamic" ValidationExpression="((\(\d{3}\) ?)|(\d{3}-))?\d{3}-\d{4}">*</asp:RegularExpressionValidator>
<div>Preferred Method of Contact</div>
<asp:DropDownList ID="contactDropDown" runat="server" CssClass="form-control">
<asp:ListItem>E-mail</asp:ListItem>
<asp:ListItem>Telephone</asp:ListItem>
</asp:DropDownList>
<div>
<asp:Button ID="submitButton" class="btn btn-primary btn-space" runat="server" Text="Submit" OnClick="submitButton_Click" />
<asp:Button ID="clearButton" class="btn btn-primary btn-space" runat="server" Text="Clear" OnClick="clearButton_Click" BackColor="#33CC33" />
</div>
<div>
<asp:Label ID="submitLabel1" runat="server" Text="Thank you for your Request." Visible="False" ForeColor="Green"></asp:Label>
</div>
<div>
<asp:Label ID="submitLabel2" runat="server" EnableViewState="False" Text="We will get back to you within 24 hours." Visible="False" ForeColor="Green"></asp:Label>
</div>
</div>
</form>
</body>
</html>
One of these all properties is receiving 'NULL' and at the time of inserting this values in database your table structure is not allowing 'NULL'.
So make sure that if you want to store 'NULL' in table then allow NULL in table structure (Table design).
You can check it using "line by line execution" of your code (using break point).

Conditional Custom Validation on 2 TextBoxes

My goal here is to build a field that will basically make one or the other textbox required. I.E. If one textbox has some value that is not null, whitespace. or empty, I want the submit button to proceed. Else I want the standard red error to stop the submit from postingback and launching the insert function. I have tried writing this, but so far no good. What can I do to make this work?
<script type="text/javascript">
function validateText(sender, args) {
if (args.value !== "") {
var textBoxB = document.getElementById('TextBox12');
args.IsValid = (TextBox12.value !== "");
}
return;
/*
if (!string.IsNullOrEmpty(TextBox12.Text + TextBox13.Text)) {
args.IsValid = true;
}
else {
if (string.IsNullOrEmpty(TextBox12.Text) && !string.IsNullOrEmpty(TextBox13.Text)) {
args.IsValid = true;
}
else if (string.IsNullOrEmpty(TextBox13.Text) && !string.IsNullOrEmpty(TextBox12.Text)) {
args.IsValid = true;
}
else {
args.IsValid = false;
}
}
*/
}
</script>
<div>
<div class="left">
<asp:Label ID="Label13" runat="server" Text="Advanced Cancellation:"></asp:Label>
</div>
<div class="right">
<asp:TextBox ID="TextBox12" runat="server"></asp:TextBox>
<asp:CustomValidator ID="CustomValidator1" runat="server"
ErrorMessage="Required"
ValidationGroup='valGroup1'
ClientValidationFunction="validateText"
OnServerValidate="ServerValidation"
ForeColor="Red"
ValidateEmptyText="true">
</asp:CustomValidator>
<asp:RegularExpressionValidator ID="RegularExpressionValidator2" runat="server"
ErrorMessage="Advanced Cancellation must be an integer."
ControlToValidate="TextBox12"
ValidationExpression="^\+?(0|[1-9]\d*)$"
ForeColor="Red">
</asp:RegularExpressionValidator>
</div>
</div>
<div>
<div class="left">
<asp:Label ID="Label14" runat="server" Text="Action Required (yyyy-MM-dd):"></asp:Label>
</div>
<div class="right">
<asp:TextBox ID="TextBox13" runat="server"></asp:TextBox>
<asp:CustomValidator ID="CustomValidator2" runat="server"
ValidationGroup='valGroup1'
ValidateEmptyText="true"
ErrorMessage="Required"
ClientValidationFunction="validateText"
OnServerValidate="ServerValidation"
ForeColor="Red">
</asp:CustomValidator>
<asp:CompareValidator
ID="CompareValidator1" runat="server"
Type="Date"
Operator="DataTypeCheck"
ControlToValidate="TextBox13"
ErrorMessage="Please enter a valid date."
ForeColor="Red">
</asp:CompareValidator>
</div>
</div>
protected void ServerValidation(object source, ServerValidateEventArgs args)
{
if (!string.IsNullOrEmpty(TextBox12.Text))
args.IsValid = !string.IsNullOrEmpty(TextBox13.Text);
}
That's what I have so far.
I have remove javascript code.Now your design part is
<div>
<div class="left">
<asp:Label ID="Label13" runat="server" Text="Advanced Cancellation:"></asp:Label>
</div>
<div class="right">
<asp:TextBox ID="TextBox12" runat="server"></asp:TextBox>
<asp:CustomValidator ID="CustomValidator1" runat="server"
ErrorMessage="Required"
ValidationGroup="valGroup1"
OnServerValidate="ServerValidation"
ForeColor="Red"
ValidateEmptyText="true">
</asp:CustomValidator>
<asp:RegularExpressionValidator ID="RegularExpressionValidator2" runat="server"
ErrorMessage="Advanced Cancellation must be an integer."
ControlToValidate="TextBox12"
ValidationExpression="^\+?(0|[1-9]\d*)$"
ForeColor="Red">
</asp:RegularExpressionValidator>
</div>
</div>
<div>
<div class="left">
<asp:Label ID="Label14" runat="server" Text="Action Required (yyyy-MM-dd):"></asp:Label>
</div>
<div class="right">
<asp:TextBox ID="TextBox13" runat="server"></asp:TextBox>
<asp:CustomValidator ID="CustomValidator2" runat="server"
ValidationGroup="valGroup1"
ValidateEmptyText="true"
ErrorMessage="Required"
OnServerValidate="ServerValidation"
ForeColor="Red">
</asp:CustomValidator>
<asp:CompareValidator
ID="CompareValidator1" runat="server"
Type="Date"
Operator="DataTypeCheck"
ControlToValidate="TextBox13"
ErrorMessage="Please enter a valid date."
ForeColor="Red">
</asp:CompareValidator>
</div>
</div>
<div>
<asp:Button ID="btnok" runat="server" ValidationGroup="valGroup1" />
</div>
and code behind is
protected void ServerValidation(object source, ServerValidateEventArgs args)
{
if (!string.IsNullOrEmpty(TextBox12.Text) || !string.IsNullOrEmpty(TextBox13.Text))
args.IsValid = true;
else
{
args.IsValid = false;
}
}
I have tested its work for me

Required field validator preventing panel to display

I am using 2 link buttons (Coordinator and Staff) which on_Click action displays corresponding panels asking for login/signup/forgotpassword. If the user select signup/forgotpassword a popup windows is popped (using ModalPopupExtender) asking for information. Everything worked fine unless and until I used required field validator within the panel which pops up when the user click on signup/forgotpassword. If I use required field validator my page run fine and when I click on any of the link button (Coordinator/Staff) nothing happens.
This is aspx code :
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
<style type = "text/css">
.modalBackground
{
background-color: gray;
}
.modalPopup
{
background-color: white;
border-width: 3px;
border-style: solid;
border-color: black;
padding-top: 10px;
padding-left: 10px;
width: 300px;
height: 140px;
}
.panel
{
background : gray;
padding : 10px;
}
div ul ul
{
display: none;
}
div ul li:hover > ul
{
display: block;
}
div ul li ul:hover > ul
{
display: block;
}
</style>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:Label ID="Label1" runat="server" Font-Bold="True" Font-Names="Arial" Font-Size="XX-Large" Text="Automated Examination System"></asp:Label><br /> <br /><br />
<asp:Panel ID = "MainPanel" runat = "server" Height="181px" Width="275px">
<ul>
<li style="margin-left: 33px; width: 169px;"> <asp:LinkButton ID = "LinkAdmin" runat = "server" onclick="LinkAdmin_Click">Coordinator</asp:LinkButton></li>
<li style="width: 172px; margin-left: 33px"> <asp:LinkButton ID="LinkStaff" runat="server" onclick="LinkStaff_Click">Staff</asp:LinkButton></li>
<li style="margin-left: 33px"> <asp:LinkButton ID = "LinkStudent" runat = "server">Student</asp:LinkButton>
<ul>
<li><asp:LinkButton ID = "LinkButton1" runat = "server">Fresh Registration</asp:LinkButton></li>
<li><asp:LinkButton ID = "LinkButton2" runat = "server">Re Registration</asp:LinkButton></li>
</ul>
</li>
</ul>
</asp:Panel>
<asp:Panel ID="InfoPanel" runat="server" style="left: 290px; top: 104px; position: absolute; height: 375px; width: 611px"><br /><br /><br />
<asp:Label ID="Label2" runat="server" Font-Bold="False" Font-Names="Arial" Font-Size="Medium" Text="The Automated Examination system will allow post graduation student and under graduation students to register their respective courses for their respective semester. "></asp:Label>
<asp:Label ID="Label3" runat="server" Font-Bold="False" Font-Names="Arial" Font-Size="Medium" Text="Once the registration process is completed for a student the system sends information to the controller of examination."></asp:Label><br />
<asp:Label ID="Label4" runat="server" Font-Bold="False" Font-Names="Arial" Font-Size="Medium" Text="Each staff will be able to enter the CIE1 and CIE2 marks based on the privileges provided by coordinator of that respective department. "></asp:Label><br />
<asp:Label ID="Label5" runat="server" Font-Bold="False" Font-Names="Arial" Font-Size="Medium" Text="Once the staff enters marks for CIE1/CIE2, they won’t be allowed to make changes later on. "></asp:Label><br />
<asp:Label ID="Label6" runat="server" Font-Bold="False" Font-Names="Arial" Font-Size="Medium" Text="After submitting the marks, the staff will be given with print out of the entered marks for further reference. "></asp:Label><br />
<asp:Label ID="Label7" runat="server" Font-Bold="False" Font-Italic="False" Font-Names="Arial" Font-Size="Medium" Text="At the end of a semester each student SGPA is calculated and the controller take a back up copy of grade cards and result sheet of all the students. "></asp:Label><br />
<asp:Label ID="Label9" runat="server" Font-Bold="False" Font-Names="Arial" Font-Size="Medium" Text="Since student grades are sensitive information certain measures are taken to prevent unauthorized access. "></asp:Label><br />
<asp:Label ID="Label8" runat="server" Font-Bold="False" Font-Names="Arial" Font-Size="Medium" Text="The system also generate the transcript of student which contains all semester marks, Course Title in that particular semester, SGPA of each semester and overall CGPA of that student. "></asp:Label>
</asp:Panel>
<asp:Panel ID="AdminLogin" runat="server" style= "left: 906px; top: 105px; position: absolute; " Visible="False" Width="430px"><br/>
<asp:Label ID="Label10" runat="server" Text="Coordinator Login"></asp:Label><br /><br />
<asp:Label ID="Label11" runat="server" Text="Select Department : "></asp:Label>
<asp:DropDownList ID="DropDownList1" runat="server" ValidationGroup="AdminLogin"></asp:DropDownList>
<asp:RequiredFieldValidator ID="AdminReq1" runat="server" ControlToValidate="DropDownList1" ErrorMessage="Department is blank" ForeColor="Red" ValidationGroup="AdminLogin"></asp:RequiredFieldValidator><br /><br />
<asp:Label ID="Label12" runat="server" Text="Select Branch : "></asp:Label>
<asp:DropDownList ID="DropDownList2" runat="server" ValidationGroup="AdminLogin"></asp:DropDownList>
<asp:RequiredFieldValidator ID="AdminReq2" runat="server" ControlToValidate="DropDownList2" ErrorMessage="Branch is blank" ForeColor="Red" ValidationGroup="AdminLogin"></asp:RequiredFieldValidator><br /><br />
<asp:Label ID="Label13" runat="server" Text="Username : "></asp:Label>
<asp:TextBox ID="AdminTxt1" runat="server" ValidationGroup="AdminLogin" style="height: 22px"></asp:TextBox>
<asp:RequiredFieldValidator ID="AdminReq3" runat="server" ControlToValidate="AdminTxt1" ErrorMessage="Username is blank" ForeColor="Red" ValidationGroup="AdminLogin"></asp:RequiredFieldValidator><br /><br />
<asp:Label ID="Label14" runat="server" Text="Password : "></asp:Label>
<asp:TextBox ID="AdminTxt2" runat="server" TextMode="Password" ValidationGroup="AdminLogin"></asp:TextBox>
<asp:RequiredFieldValidator ID="AdminReq4" runat="server" ControlToValidate="AdminTxt2" ErrorMessage="Password is blank" ForeColor="Red" ValidationGroup="AdminLogin"></asp:RequiredFieldValidator><br /><br />
<asp:Button ID="AdminLog" runat="server" Text="Login" Width="80px" ValidationGroup="AdminLogin" />
<asp:Button ID="AdminSignUp" runat="server" Text="New Coordinator" Width="110px"/>
<asp:Button ID="AdminForPwd" runat="server" Text="Forgot Password" />
</asp:Panel>
<asp:Panel ID="StaffLogin" runat="server" style="left: 906px; top: 105px; position: absolute;" Visible="False" Width="430px"><br />
<asp:Label ID="Label15" runat="server" Text="Staff Login"></asp:Label><br /><br />
<asp:Label ID="Label16" runat="server" Text="Username : "></asp:Label>
<asp:TextBox ID="StaffTxt1" runat="server" Width="127px" ValidationGroup="StaffLogin"></asp:TextBox>
<asp:RequiredFieldValidator ID="StaffReq1" runat="server" ControlToValidate=" StaffTxt1" ErrorMessage="Username is blank" ForeColor="Red" ValidationGroup="StaffLogin"></asp:RequiredFieldValidator><br /><br />
<asp:Label ID="Label17" runat="server" Text="Password : "></asp:Label>
<asp:TextBox ID="StaffTxt2" runat="server" TextMode="Password" ValidationGroup="StaffLogin"></asp:TextBox>
<asp:RequiredFieldValidator ID="StaffReq2" runat="server" ControlToValidate=" StaffTxt2" ErrorMessage="Password is blank" ForeColor="Red" ValidationGroup="StaffLogin"></asp:RequiredFieldValidator><br /><br />
<asp:Button ID="StaffLog" runat="server" Text="Login" Width="80px" ValidationGroup="StaffLogin" />
<asp:Button ID="StaffSignUp" runat="server" Text="New Staff" Width="82px"/>
<asp:Button ID="StaffForPwd" runat="server" Text="Forgot Password" Width="110px" />
</asp:Panel>
<asp:Panel ID="StaffSP" CssClass="modalPopup" style="display: none" runat="server">
<asp:Label ID="Label18" runat="server" Text="Staff Sign Up" Font-Size="XX-Large"></asp:Label><br /><br />
<asp:Label ID="Label19" runat="server" Text="Enter Course Code : "></asp:Label>
<asp:TextBox ID="StaffSPTxt1" runat="server"></asp:TextBox>
<asp:RequiredFieldValidator ID="StaffSPReq1" runat="server" ErrorMessage="Course Code is BLANK" ForeColor="Red" ControlToValidate="StaffSPTxt1"></asp:RequiredFieldValidator><br /><br />
<asp:Label ID="Label20" runat="server" Text="Enter Password : "></asp:Label>
<asp:TextBox ID="StaffSPTxt2" runat="server" TextMode="Password"></asp:TextBox>
<asp:RequiredFieldValidator ID="StaffSPReq2" runat="server" ErrorMessage="Password is BLANK" ForeColor="Red" ControlToValidate="StaffSPTxt2"></asp:RequiredFieldValidator><br /><br />
<asp:Label ID="Label21" runat="server" Text="Retype Password : "></asp:Label>
<asp:TextBox ID="StaffSPTxt3" runat="server" TextMode="Password"></asp:TextBox>
<asp:CompareValidator ID="StaffSPCom1" runat="server" ErrorMessage="Password Mismatch" ForeColor="Red" ControlToCompare="StaffSPTxt2" ControlToValidate="StaffSPTxt3"></asp:CompareValidator><br /><br />
<asp:Label ID="Label22" runat="server" Text="Enter Password Hint : "></asp:Label>
<asp:TextBox ID="StaffSPTxt4" runat="server" TextMode="Password"></asp:TextBox>
<asp:RequiredFieldValidator ID="StaffSPReq3" runat="server" ErrorMessage="Password Hint is BLANK" ForeColor="Red" ControlToValidate="StaffSPTxt4"></asp:RequiredFieldValidator><br /><br />
<asp:Button ID="Button3" runat="server" Text="Sign Up" />
<asp:Button ID="Button4" runat="server" Text="Cancel" />
</asp:Panel>
<asp:Panel ID="StaffFP" CssClass="modalPopup" style="display: none" runat="server">
<asp:Label ID="Label23" runat="server" Text="Staff Forgot Password" Font-Size="XX-Large"></asp:Label><br /><br />
<asp:Label ID="Label24" runat="server" Text="Enter Username : "></asp:Label>
<asp:TextBox ID="StaffFPTxt1" runat="server"></asp:TextBox>
<asp:RequiredFieldValidator ID="StaffFPReq1" runat="server" ErrorMessage="Username is BLANK" ForeColor="Red" ControlToValidate="StaffFPTxt1"></asp:RequiredFieldValidator><br /><br />
<asp:Label ID="Label25" runat="server" Text="Enter Password Hint : "></asp:Label>
<asp:TextBox ID="StaffFPTxt2" runat="server" TextMode="Password"></asp:TextBox>
<asp:RequiredFieldValidator ID="StaffFPReq2" runat="server" ErrorMessage="Hint is BLANK" ForeColor="Red" ControlToValidate="StaffFPTxt2"></asp:RequiredFieldValidator><br /><br />
<asp:Button ID="Button5" runat="server" Text="GetPassword" />
<asp:Button ID="Button6" runat="server" Text="Cancel" />
</asp:Panel>
<asp:Panel ID="AdminSP" CssClass="modalPopup" style="display: none" runat="server">
<asp:Label ID="Label26" runat="server" Text="Coordinator Sign Up" Font-Size="XX-Large"></asp:Label><br /><br />
<asp:Label ID="Label27" runat="server" Text="Select Department : "></asp:Label>
<asp:DropDownList ID="AdminSPDrp1" runat="server" ></asp:DropDownList>
<asp:RequiredFieldValidator ID="AdminSPReq1" runat="server" ErrorMessage="Department is BLANK" ForeColor="Red" ControlToValidate="AdminSPDrp1"></asp:RequiredFieldValidator><br /><br />
<asp:Label ID="Label28" runat="server" Text="Select Branch : "></asp:Label>
<asp:DropDownList ID="AdminSPDrp2" runat="server" ></asp:DropDownList>
<asp:RequiredFieldValidator ID="AdminSPReq2" runat="server" ErrorMessage="Branch is BLANK" ForeColor="Red" ControlToValidate="AdminSPDrp2"></asp:RequiredFieldValidator><br /><br />
<asp:Label ID="Label29" runat="server" Text="Enter Username : "></asp:Label>
<asp:TextBox ID="AdminSPTxt1" runat="server"></asp:TextBox>
<asp:RequiredFieldValidator ID="AdminSPReq3" runat="server" ErrorMessage="Username is BLANK" ForeColor="Red" ControlToValidate="AdminSPTxt1"></asp:RequiredFieldValidator><br /><br />
<asp:Label ID="Label30" runat="server" Text="Enter Password : "></asp:Label>
<asp:TextBox ID="AdminSPTxt2" runat="server" TextMode="Password"></asp:TextBox>
<asp:RequiredFieldValidator ID="AdminSPReq4" runat="server" ErrorMessage="Password is BLANK" ForeColor="Red" ControlToValidate="AdminSPTxt2"></asp:RequiredFieldValidator><br /><br />
<asp:Label ID="Label31" runat="server" Text="Retype Password : "></asp:Label>
<asp:TextBox ID="AdminSPTxt3" runat="server" TextMode="Password"></asp:TextBox>
<asp:CompareValidator ID="AdminSPCom1" runat="server" ControlToValidate = "AdminSPTxt3" ControlToCompare = "AdminSPTxt2" ErrorMessage="Password Mismatch" ForeColor="Red"></asp:CompareValidator><br /><br />
<asp:Label ID="Label32" runat="server" Text="Enter Password Hint : "></asp:Label>
<asp:TextBox ID="AdminSPTxt4" runat="server" TextMode="Password"></asp:TextBox>
<asp:RequiredFieldValidator ID="AdminSPReq5" runat="server" ErrorMessage="Hint is BLANK" ForeColor="Red" ControlToValidate="AdminSPTxt4"></asp:RequiredFieldValidator><br /><br />
<asp:Button ID="Button7" runat="server" Text="Sign Up" />
<asp:Button ID="Button8" runat="server" Text="Cancel" />
</asp:Panel>
<asp:Panel ID="AdminFP" CssClass="modalPopup" style="display: none" runat="server">
<asp:Label ID="Label33" runat="server" Text="Coordinator Forgot Password" Font-Size="XX-Large"></asp:Label><br /><br />
<asp:Label ID="Label34" runat="server" Text="Select Department : "></asp:Label>
<asp:DropDownList ID="AdminFPDrp1" runat="server" ></asp:DropDownList>
<asp:RequiredFieldValidator ID="AdminFPReq1" runat="server" ErrorMessage="Department is BLANK" ForeColor="Red" ControlToValidate="AdminFPDrp1"></asp:RequiredFieldValidator><br /><br />
<asp:Label ID="Label35" runat="server" Text="Select Branch : "></asp:Label>
<asp:DropDownList ID="AdminFPDrp2" runat="server" ></asp:DropDownList>
<asp:RequiredFieldValidator ID="AdminFPReq2" runat="server" ErrorMessage="Branch is BLANK" ForeColor="Red" ControlToValidate="AdminFPDrp2"></asp:RequiredFieldValidator><br /><br />
<asp:Label ID="Label36" runat="server" Text="Enter Username : "></asp:Label>
<asp:TextBox ID="AdminFPTxt1" runat="server"></asp:TextBox>
<asp:RequiredFieldValidator ID="AdminFPReq3" runat="server" ErrorMessage="Username is BLANK" ForeColor="Red" ControlToValidate="AdminFPTxt1"></asp:RequiredFieldValidator><br /><br />
<asp:Label ID="Label37" runat="server" Text="Enter Password Hint : "></asp:Label>
<asp:TextBox ID="AdminFPTxt2" runat="server" TextMode="Password"></asp:TextBox>
<asp:RequiredFieldValidator ID="AdminFPReq4" runat="server" ErrorMessage="Hint is BLANK" ForeColor="Red" ControlToValidate="AdminFPTxt2"></asp:RequiredFieldValidator><br /><br />
<asp:Button ID="Button9" runat="server" Text="Sign Up" />
<asp:Button ID="Button10" runat="server" Text="Cancel" />
</asp:Panel>
<asp:ScriptManager ID="ScriptManager1" runat="server"></asp:ScriptManager>
<asp:ModalPopupExtender ID="ModalPopupExtender1" BackgroundCssClass="modalBackground" PopupControlID = "StaffSP" CancelControlID = "Button4" TargetControlID = "StaffSignUp" runat="server"></asp:ModalPopupExtender>
<asp:ModalPopupExtender ID="ModalPopupExtender2" BackgroundCssClass="modalBackground" PopupControlID = "StaffFP" CancelControlID = "Button6" TargetControlID = "StaffForPwd" runat="server"></asp:ModalPopupExtender>
<asp:ModalPopupExtender ID="ModalPopupExtender3" BackgroundCssClass="modalBackground" PopupControlID = "AdminSP" CancelControlID = "Button8" TargetControlID = "AdminSignUp" runat="server"></asp:ModalPopupExtender>
<asp:ModalPopupExtender ID="ModalPopupExtender4" BackgroundCssClass="modalBackground" PopupControlID = "AdminFP" CancelControlID = "Button10" TargetControlID = "AdminForPwd" runat="server"></asp:ModalPopupExtender>
</div>
</form>
</body>
</html>
This is code behind page :
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
public partial class MasterFinal : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
protected void LinkAdmin_Click(object sender, EventArgs e)
{
AdminLogin.Visible = true;
StaffLogin.Visible = false;
}
protected void LinkStaff_Click(object sender, EventArgs e)
{
AdminLogin.Visible = false;
StaffLogin.Visible = true;
}
}

multiple forms run at server make visible to client asp.net

i have made registeration form, forgot password and login form in a single aspx page . I am using css to style the whole form. I am using 3 form tags. Here is code:
ASMX
<form id="form1" runat="server" visible="true">
<ul>
<li>
<asp:TextBox ID="email" runat="server" TextMode="email" placeholder="Email" OnTextChanged="email_TextChanged"></asp:TextBox>
<asp:RequiredFieldValidator ID="RequiredFieldValidator1" runat="server" ControlToValidate="email" Display="Dynamic" ErrorMessage="RequiredFieldValidator">*Requied</asp:RequiredFieldValidator>
</li>
<li>
<asp:TextBox ID="password" runat="server" TextMode="Password" placeholder="Password" OnTextChanged="password_TextChanged"></asp:TextBox>
<asp:RequiredFieldValidator ID="RequiredFieldValidator2" runat="server" ControlToValidate="password" Display="Dynamic" ErrorMessage="RequiredFieldValidator">*Requied</asp:RequiredFieldValidator>
</li>
<li>
<asp:Button ID="Button1" runat="server" Text="Button" OnClick="Button1_Click" />
</li>
<li>
<asp:Label ID="Invalid" runat="server" Text="Invalid Username or Password" Visible="False" ></asp:Label>
<asp:Label ID="Try" runat="server" Text="You can't try again ,Register Your Self" Visible="False"></asp:Label>
</li>
</ul>
</form>
<form runat="server" id="form2" visible="false">
<ul>
<li>
<asp:TextBox ID="username" runat="server" MaxLength="15" placeholder="UserName" OnTextChanged="username_TextChanged"></asp:TextBox>
<asp:RequiredFieldValidator ID="RequiredFieldValidator3" runat="server" ControlToValidate="username" ErrorMessage="RequiredFieldValidator" ForeColor="Red">*Please Input user name</asp:RequiredFieldValidator>
<asp:Label ID="userchk" runat="server" ForeColor="Red"></asp:Label>
</li>
<li>
<asp:TextBox ID="EmailR" runat="server" placeholder="Email (must be valid)" OnTextChanged="EmailR_TextChanged"></asp:TextBox>
<asp:RequiredFieldValidator ID="RequiredFieldValidator6" runat="server" ControlToValidate="EmailR" ErrorMessage="RequiredFieldValidator" ForeColor="Red">*Please Input email</asp:RequiredFieldValidator>
<asp:RegularExpressionValidator ID="RegularExpressionValidator2" runat="server" ControlToValidate="EmailR" Display="Dynamic" ValidationExpression="\w+([-+.']\w+)*#\w+([-.]\w+)*\.\w+([-.]\w+)*" ErrorMessage="RegularExpressionValidator" ForeColor="Red">Input Valid Email</asp:RegularExpressionValidator>
</li>
<li>
<asp:TextBox ID="FirstName" runat="server" placeholder="FirstName" MaxLength="15" OnTextChanged="FirstName_TextChanged"></asp:TextBox>
<asp:RequiredFieldValidator ID="RequiredFieldValidator8" runat="server" ControlToValidate="FirstName" ErrorMessage="RequiredFieldValidator" ForeColor="Red">*Please Input first name</asp:RequiredFieldValidator>
<asp:Label ID="chkemail" runat="server" ForeColor="Red"></asp:Label>
</li>
<li>
<asp:TextBox ID="LastName" runat="server" placeholder="Lastname" MaxLength="15" OnTextChanged="TextBox3_TextChanged"></asp:TextBox>
<asp:RequiredFieldValidator ID="RequiredFieldValidator4" runat="server" ControlToValidate="LastName" ErrorMessage="RequiredFieldValidator" ForeColor="Red">*Please Input Last name</asp:RequiredFieldValidator>
</li>
<li>
<asp:TextBox ID="Pass" runat="server" placeholder="Password" TextMode="Password" MaxLength="15" OnTextChanged="Pass_TextChanged"></asp:TextBox>
<asp:RequiredFieldValidator ID="RequiredFieldValidator5" runat="server" ControlToValidate="Pass" Display="Dynamic" ErrorMessage="RequiredFieldValidator" ForeColor="Red">*Please Input password</asp:RequiredFieldValidator>
</li>
<li>
<asp:TextBox ID="Cpass" runat="server" placeholder="Confirm Password" TextMode="Password" MaxLength="15" OnTextChanged="Cpass_TextChanged"></asp:TextBox>
<asp:RequiredFieldValidator ID="RequiredFieldValidator7" runat="server" ControlToValidate="Cpass" ErrorMessage="RequiredFieldValidator" ForeColor="Red">*Please Enter the Confirm Password </asp:RequiredFieldValidator>
</ul>
</form>
<form runat="server" visible="false" id="form3">
<ul>
<li>
<asp:TextBox ID="SendEmail" runat="server" TextMode="Email" placeholder="Enter Email" OnTextChanged="SendEmail_TextChanged"></asp:TextBox>
<asp:RequiredFieldValidator ID="RequiredFieldValidator11" runat="server" ControlToValidate="SendEmail" Display="Dynamic" ErrorMessage="RequiredFieldValidator">*Requied</asp:RequiredFieldValidator>
</li>
<li>
<asp:Button runat="server" text="Send email" OnClick="SendMail_Click" CssClass="button" Visible="true" CausesValidation="False"/>
</li>
<li>
<asp:Label ID="ml" runat="server" Text="Email sended Sucessfully" Visible="False"></asp:Label>
<asp:Label ID="ml0" runat="server" Text="Email Didn't Match " Visible="False"></asp:Label>
</li>
</ul>
</form>
I used following Js in toglling categories:
JS
<script>
$(document).ready(function () {
$("#list1").click(function () {
$("#form1").fadeIn("slow");
$("#form2").css("display", "none");
$("#form3").css("display", "none");
});
$("#list2").click(function () {
$("#form2").fadeIn("slow");
$("#form2").css("visible", "true");
$("#form1").css("display", "none");
$("#form3").css("display", "none");
});
$("#list3").click(function () {
$("#form3").fadeIn("slow");
$("#form3").css("visible", "true");
$("#form2").css("display", "none");
$("#form1").css("display", "none");
});
});
</script>
and here is my css FORMS
I have to use multiple forms in any case .. can anyone help please??

Categories

Resources