The world’s Largest Sharp Brain Virtual Experts Marketplace Just a click Away
Levels Tought:
Elementary,Middle School,High School,College,University,PHD
| Teaching Since: | Jul 2017 |
| Last Sign in: | 337 Weeks Ago, 1 Day Ago |
| Questions Answered: | 15833 |
| Tutorials Posted: | 15827 |
MBA,PHD, Juris Doctor
Strayer,Devery,Harvard University
Mar-1995 - Mar-2002
Manager Planning
WalMart
Mar-2001 - Feb-2009
I need input validation added to these pages. Let me know if there are any questions
I need input handling added to this page. (guestbook.aspx)
aspx
<%@PageLanguage="C#"AutoEventWireup="true"CodeFile="guestbook.aspx.cs"Inherits="guestbook"%>
<!DOCTYPEhtml>
<htmlxmlns="http://www.w3.org/1999/xhtml">
<headrunat="server">
<title></title>
</head>
<body>
<formid="form1"runat="server">
<div>
<asp:DataGridID="dg"runat="server">
</asp:DataGrid>
</div>
</form>
</body>
</html>
Aspx.cs
using System;
usingSystem.Collections.Generic;
usingSystem.Linq;
usingSystem.Web;
usingSystem.Web.UI;
usingSystem.Web.UI.WebControls;
publicpartialclassguestbook : System.Web.UI.Page
{
protectedvoidPage_Load(object sender, EventArgs e)
{
}
}
Here are some helpful hints
aspx.cs changes
protected void insertRow(object o, EventArgs e)
{
if (Page.IsValid == false) return; // NEED THIS LINE TO PREVENT INSERTING BAD DATA INTO THE DATABASE
.aspx changes:
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="myguestbook.aspx.cs" Inherits="myguestbook" %>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:DataGrid ID="dg" runat="server"></asp:DataGrid>
</div>
<asp:ValidationSummary runat="server" HeaderText="There were errors on the page:" />
<asp:RequiredFieldValidator runat="server"
ControlToValidate="txName"
ErrorMessage="Name is required."> *
</asp:RequiredFieldValidator>
Name: <input type="text" id="txName" runat="server" />
<asp:RegularExpressionValidator runat="server" display="Dynamic"
ControlToValidate ="txName"
ErrorMessage="Name must be one or more letters only (<40)"
ValidationExpression="[A-Za-z ]{1,40}" />
<br />
<asp:RequiredFieldValidator runat="server"
ControlToValidate="txAge"
ErrorMessage="Age is required."> *
</asp:RequiredFieldValidator>
Age: <input type="text" id="txAge" runat="server" />
<asp:RegularExpressionValidator runat="server" display="Dynamic"
ControlToValidate ="txAge"
ErrorMessage="Age must be only numbers"
ValidationExpression="[0-9]{1,3}" />
<br />
<asp:RequiredFieldValidator runat="server"
ControlToValidate="txComment"
ErrorMessage="Comment is required."> *
</asp:RequiredFieldValidator>
Comment: <input type="text" id="txComment" runat="server" />
<asp:RegularExpressionValidator runat="server" display="Dynamic"
ControlToValidate ="txComment"
ErrorMessage="Comment can only contain letters and spaces (<80)"
ValidationExpression="[A-Za-z ]{1,80}" />
<br />
<input type="button" value="Insert" onserverclick="insertRow" runat="server" />
</form>
</body>
</html>
----------- ----------- H-----------ell-----------o S-----------ir/-----------Mad-----------am ----------- Th-----------ank----------- yo-----------u f-----------or -----------you-----------r i-----------nte-----------res-----------t a-----------nd -----------buy-----------ing----------- my----------- po-----------ste-----------d s-----------olu-----------tio-----------n. -----------Ple-----------ase----------- pi-----------ng -----------me -----------on -----------cha-----------t I----------- am----------- on-----------lin-----------e o-----------r i-----------nbo-----------x m-----------e a----------- me-----------ssa-----------ge -----------I w-----------ill----------- be----------- qu-----------ick-----------ly