<%@ Page Title="" Language="C#" MasterPageFile="~/Site.Master" AutoEventWireup="true" CodeBehind="ReviewAdd.aspx.cs" Inherits="TailspinSpyworks.ReviewAdd" %><asp:Content ID="Content1" ContentPlaceHolderID="HeadContent" runat="server"></asp:Content><%@ Register Assembly="AjaxControlToolkit" Namespace="AjaxControlToolkit.HTMLEditor" TagPrefix="cc1" %><%@ Register Assembly="AjaxControlToolkit" Namespace="AjaxControlToolkit" TagPrefix="asp" %><asp:Content ID="Content2" ContentPlaceHolderID="MainContent" runat="server"><asp:ToolkitScriptManager ID="ToolkitScriptManager1" runat="server"></asp:ToolkitScriptManager><div class="ContentHead">Add Review - <asp:label id="ModelName" runat="server" /></div><div style="padding: 20px; border-style:solid; border-width: 1px"><span class="NormalBold">Name</span><br /><asp:TextBox id="Name" runat="server" Width="400px" /><br /><asp:RequiredFieldValidator runat="server" id="RequiredFieldValidator1" ControlToValidate="Name" Display="Dynamic" CssClass="ValidationError" ErrorMessage="'Name' must not be left blank." /><br /><span class="NormalBold">Email</span><br /><asp:TextBox id="Email" runat="server" Width="400px" /><br /><asp:RequiredFieldValidator runat="server" id="RequiredFieldValidator2" ControlToValidate="Email" Display="Dynamic" CssClass="ValidationError" ErrorMessage="'Email' must not be left blank." /><br /><hr /><br /><span class="NormalBold">Rating</span><br /><br /><asp:RadioButtonList ID="Rating" runat="server"><asp:ListItem value="5" selected="True" Text='<img src="Styles/Images/reviewrating5.gif" alt=""> (Five Stars) ' /><asp:ListItem value="4" selected="True" Text='<img src="Styles/Images/reviewrating4.gif" alt=""> (Four Stars) ' /><asp:ListItem value="3" selected="True" Text='<img src="Styles/Images/reviewrating3.gif" alt=""> (Three Stars) ' /><asp:ListItem value="2" selected="True" Text='<img src="Styles/Images/reviewrating2.gif" alt=""> (Two Stars) ' /><asp:ListItem value="1" selected="True" Text='<img src="Styles/Images/reviewrating1.gif" alt=""> (One Stars) ' /></asp:RadioButtonList><br /><hr /><br /><span class="NormalBold">Comments</span><br /><cc1:Editor ID="UserComment" runat="server" /><asp:RequiredFieldValidator runat="server" id="RequiredFieldValidator3" ControlToValidate="UserComment" Display="Dynamic" CssClass="ValidationError" ErrorMessage="Please enter your comment." /><br /><br /><asp:ImageButton ImageURL="Styles/Images/submit.gif" runat="server" CausesValidation="true" id="ReviewAddBtn" onclick="ReviewAddBtn_Click" /><br /><br /><br /></div></asp:Content> using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.Web.UI; using System.Web.UI.WebControls; using System.Diagnostics; using TailspinSpyworks.Data_Access; namespace TailspinSpyworks { public partial class ReviewAdd : System.Web.UI.Page { protected void Page_Load(object sender, EventArgs e) { if (!String.IsNullOrEmpty(Request.QueryString["ProductID"])) { int productID = 0; Int32.TryParse(Request["productID"].ToString(), out productID); using (CommerceEntities db = new CommerceEntities()) { try { var thisProduct = (from p in db.Products where p.ProductID == productID select p).FirstOrDefault(); ModelName.Text = thisProduct.ModelName; } catch (Exception exp) { throw new Exception("ERROR: Unable to Add Product Review - " + exp.Message.ToString(), exp); } } } else { Debug.Fail("ERROR : We should never get to ReviewAdd.aspx without a ProductId."); throw new Exception("ERROR : It is illegal to load ReviewAdd.aspx without setting a ProductId."); } } protected void ReviewAddBtn_Click(object sender, ImageClickEventArgs e) { try { if (Page.IsValid == true) { // Obtain ProductID from Page State int productID = Int32.Parse(Request["productID"]); // Obtain Rating number of RadioButtonList int rating = Int32.Parse(Rating.SelectedItem.Value); // Add Review to ReviewsDB. HtmlEncode before entry using (CommerceEntities db = new CommerceEntities()) { try { ShoppingCart cartadd = new ShoppingCart(); Review newReview = new Review() { ProductID = productID, Rating = rating, CustomerName = HttpUtility.HtmlEncode(Name.Text), CustomerEmail = HttpUtility.HtmlEncode(Email.Text), Comments = HttpUtility.HtmlEncode(UserComment.Content) }; db.Reviews.AddObject(newReview); db.SaveChanges(); } catch (Exception exp) { throw new Exception("ERROR: Unable to Update Cart Item - " + exp.Message.ToString(), exp); } } Response.Redirect("ProductDetails.aspx?ProductID=" + productID); } Response.Redirect("ProductList.aspx"); } catch (Exception ex) { } } protected void LikeRating_Changed(object sender, AjaxControlToolkit.RatingEventArgs e) { } } }
The validation controls not working in this page.Not able to configure what the problem is