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: | 313 Weeks Ago, 6 Days 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