Wrox Programmer Forums
BOOK: Beginning ASP.NET Web Pages with WebMatrix
This is the forum to discuss the Wrox book Beginning ASP.NET Web Pages with WebMatrix by Mike Brind, Imar Spaanjaars ; ISBN: 978-1-1180-5048-4
Welcome to the p2p.wrox.com Forums.

You are currently viewing the BOOK: Beginning ASP.NET Web Pages with WebMatrix section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
Old July 3rd, 2012, 04:50 AM
Registered User
Join Date: Jul 2012
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Question Comment Section in WebMatrix

Hi Guys. i have created a comment section in Details page but when someone comments in one special page in can be seen in every page of Details page i don't know where is the problem. thanks for helping me.
here's the code

dynamic item = null;
if(!Request["id"].IsEmpty() && Request["id"].IsInt()) {
var db = Database.Open("Classifieds");
var sql = "SELECT * FROM Items, Categories WHERE Id = @0";
item = db.QuerySingle(sql, Request["id"]);
Page.Title = item.Title + "-" + item.Id;

if(IsPost) {
if(Request["name"].IsEmpty()) {
ModelState.AddError("name", "Please provide a name");
if(Request["email"].IsEmpty()) {
ModelState.AddError("email", "Please enter your E-mail");
if(!Request["email"].IsEmpty() && !Functions.IsValidEmail(Request["email"])) {
ModelState.AddError("email","Please provide a valid email");
if(Request["comment"].IsEmpty()) {
ModelState.AddError("comment", "Please fill the comment form");
if(!ModelState.IsValid) {
ModelState.AddFormError("Please fix the errors below before submitting your comment");
else {
var db = Database.Open("Classifieds");
var msql = @"INSERT INTO Comments (Name, Email, Comment, DatePosted) VALUES (@0, @1, @2, GetDate())";
var parameters = new[]{Request["name"],Request["email"],Request["comment"]};
db.Execute(msql, parameters) ;
Response.Redirect("~/Details.cshtml?id=" + item.Id);
var dbs = Database.Open("Classifieds");
var tsql = @"SELECT Id, Name, Email, Comment, DatePosted FROM Comments";
var data = dbs.Query(tsql).OrderByDescending(c => c.Id);


<!DOCTYPE html>

<html lang="en">
<meta charset="utf-8" />
<script type="text/javascript">
function resetForm() {
document.getElementById("name0").value = "";
document.getElementById("email0").value = "";
document.getElementById("comment0").value = "";
@if(item != null) {
<p>Price: @item.Price.ToString("c")</p>
<p>Condition: @item.Condition</p>
<p>Posted on @item.DatePosted.ToString("D") in the @item.Category category</p>



<form id="post-advert" method="post" action="@Href("~/Details.cshtml?id=" + item.Id)">
<div data-href="@Href("~/Details.cshtml?id=" + item.Id)">
@if(item.Id == Request["id"].AsInt()) {
foreach(var dt in data) {
<div id="namecomment">Posted by @dt.Name at @dt.DatePosted</div><br>
<div id="commentsection">@dt.Comment</div><hr>


<div><label for="name">Name* : </label></div>

<div><input type="text" name="name" id="name0" value="@Request["name"]">

<div><label for="email">E-mail* : </label></div>

<input type="text" name="email" id="email0" value="@Request["email"]">

<div><label for="comment">Comment* : </label></div>
<textarea name="comment" cols="40" rows="10" id="comment0" >@Request["comment"]</textarea>
<div><input type="submit" value="Post Comment"></div>

Similar Threads
Thread Thread Starter Forum Replies Last Post
WebMatrix Beta 2 Anyone? jpjamie BOOK: Beginning ASP.NET Web Pages with WebMatrix 7 September 24th, 2012 02:57 PM
ASP.NET using Webmatrix yashvanjani ASP.NET 2.0 Basics 1 July 1st, 2006 04:28 PM
Webmatrix chapter 3 jdelpay ASP.NET 1.0 and 1.1 Basics 0 October 18th, 2004 02:35 PM
Dreamweaver and webmatrix paggy Dreamweaver (all versions) 0 March 10th, 2004 03:30 AM
Comment Out Section Of VB Code ritag VB How-To 3 September 10th, 2003 04:18 PM

Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.