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 January 11th, 2012, 12:52 PM
Authorized User
 
Join Date: Mar 2011
Posts: 74
Thanks: 21
Thanked 2 Times in 2 Posts
Default Strange Submit Issue

Code:
Please enter your first name: <input type="text" size=25 name="FirstName" value="@Request["FirstName"]" />@Html.ValidationMessage("FirstName")
</td>
 <td rowspan="2" align="left" valign="middle">
@Html.Hidden("ApplicationName", "My Application")
@Html.Hidden("WeekNumber", 2)   
<input type="submit" value="Submit" onClick="willReset=confirm('Submit this Exam?');return willReset;">
<input type="reset" value="Clear & Reset" onClick="willReset=confirm('Are you sure you want to Reset?');return willReset;">
When the form is submitted, the page validates and FirstName is correctly displayed using @Request["FirstName"] in my "thanks for submitting," however, when I check the database, the column for FirstName has the integer 2 entered very time. When I change the WeekNumber to a different integer THAT integer is entered into the database as FirstName, so it has something to do with the WeeKNumber "@Html.Hidden"

To compound the issue, the LastName database column has the value for FirstName entered!

I strongly suspect it's got something to do with my "@Html.Hidden" fields.

I know...using <table></table> code, works for now.

At this writing, I'm working on a process of elimination, and will eventually find it, but for the time being: What's going on here?

I realize, this is not assocated with any "Try It Out," but it's relevant to Chapter 5 and may help others with the same issue. Will keep future posts book specific.


JJ
 
Old January 11th, 2012, 01:02 PM
Imar's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
Default

Hi there,

Can you post the full code for the page? A bit hard to tell based on this code alone.

Cheers,

Imar
__________________
Imar Spaanjaars
http://Imar.Spaanjaars.Com
Follow me on Twitter

Author of Beginning ASP.NET 4.5 : in C# and VB, Beginning ASP.NET Web Pages with WebMatrix
and Beginning ASP.NET 4 : in C# and VB.
Did this post help you? Click the button below this post to show your appreciation!
 
Old January 11th, 2012, 01:32 PM
Authorized User
 
Join Date: Mar 2011
Posts: 74
Thanks: 21
Thanked 2 Times in 2 Posts
Default

Quote:
Originally Posted by Imar View Post
Hi there,

Can you post the full code for the page? A bit hard to tell based on this code alone.

Cheers,

Imar
Sorry and should have realized THAT! However, I have 1,446 lines of code, and there are confidentiality issues! I have almost the exact same code running on other pages, so it's frustrating me at this time. If the problem continues, I'll remove the confidential semantics and post the code. For now, I'll just keep hacking away, sleep on it and probably figure it all out in the shower (as has happened before a few times) LOL!

Thanks for the offer!

JJ
 
Old January 11th, 2012, 02:48 PM
Authorized User
 
Join Date: Mar 2011
Posts: 74
Thanks: 21
Thanked 2 Times in 2 Posts
Default Edited Code

OK here is the the code that I feel is the most relevant. The <body> is remvoed as it just lists the questions (Q1, Q2, Q3 etc.) with associated comments (Q1Comments, Q2Comments, Q3Commetns) separated with <div></div> tags. There are also associated validation tags for each question. The page runs fine, so it's got something to do with the <form> and the data for FirstName and WeeKNumber. I can change the hidden value for WeekNumber to any integer and for some reason FirstName in the database gets that value inserted!

It's probably something simple I'm missing, but it's annoying because I have other exams modeled on this exam, that don't have this issue and the code except for the questions and the hidden values is the almost exactly the same.

There's probably a better and more efficient way to code this, but for now (thanks to WebMatrix and your book!) getting this to work is fantastic!


Code:
<!DOCTYPE html>

<html lang="en">
    <head>
        <meta charset="utf-8" />
        <title>Online Exam - Week I</title>
    
        <link rel="stylesheet" href="../Styles/Style1.css">
        
                     
                        
        </head>
    <body>
 
        
<div align="center">

<table width="650" cellspacing="0" cellpadding="0" border="0" height="107">
<tr> 
<td align="left" valign="top" > 
<font face="Arial" size="2">    

	 
<meta http-equiv="Content-Type" content="text/html; charset=windows-1252">
<title>Week I Exam</title>

<form action=""  method="post"> 
  
    
@if(IsPost) {
    var errors = String.Empty;
    
    if(Request["Q1"].IsEmpty()) {
        errors += "<li>Question 1</li>";
    }
     if(Request["Q2"].IsEmpty()) {
        errors += "<li>Question 2</li>";
    }
     if(Request["Q3"].IsEmpty()) {
        errors += "<li>Question 3</li>";
    }
     if(Request["Q4"].IsEmpty()) {
        errors += "<li>Question 4</li>";
    }
     if(Request["Q5"].IsEmpty()) {
        errors += "<li>Question 5</li>";
    }
     if(Request["Q6"].IsEmpty()) {
        errors += "<li>Question 6</li>";
    }
     if(Request["Q7"].IsEmpty()) {
        errors += "<li>Question 7</li>";
    }
     if(Request["Q8"].IsEmpty()) {
        errors += "<li>Question 8</li>";
    }
     if(Request["Q9"].IsEmpty()) {
        errors += "<li>Question 9</li>";
    }
     if(Request["Q10"].IsEmpty()) {
        errors += "<li>Question 10</li>";
    }
     if(Request["Q11"].IsEmpty()) {
        errors += "<li>Question 11</li>";
    }
     if(Request["Q12"].IsEmpty()) {
        errors += "<li>Question 12</li>";
    }
     if(Request["Q13"].IsEmpty()) {
        errors += "<li>Question 13</li>";
    }
     if(Request["Q14"].IsEmpty()) {
        errors += "<li>Question 14</li>";
    }
     if(Request["Q15"].IsEmpty()) {
        errors += "<li>Question 15</li>";
    }
     if(Request["Q16"].IsEmpty()) {
        errors += "<li>Question 16</li>";
    }
    if(errors.IsEmpty()) {
    
    
    
    <div align="center">
    <div align="left" class="boxAnswers1">   
    <div><strong>Thanks Dr. @Request["FirstName"] @Request["LastName"]!<br/>
        Submitted: @DateTime.Now.ToString()<br/>
        Your submitted answers:</strong></div><br/>
        <div>Question 1: @Request["Q1"]</div> 
    <div>Comments: @Request["Q1Comments"]</div> 
         <div>Question 2: @Request["Q2"]</div>
    <div>Comments: @Request["Q2Comments"]</div> 
     <div>Question 3: @Request["Q3"]</div>
    <div>Comments: @Request["Q3Comments"]</div> 
     <div>Question 4: @Request["Q4"]</div>
    <div>Comments: @Request["Q4Comments"]</div> 
     <div>Question 5: @Request["Q5"]</div>
    <div>Comments: @Request["Q5Comments"]</div> 
     <div>Question 6: @Request["Q6"]</div>
    <div>Comments: @Request["Q6Comments"]</div> 
     <div>Question 7: @Request["Q7"]</div>
    <div>Comments: @Request["Q7Comments"]</div> 
     </div> 
     <div align="left" class="boxAnswers2">
     <div>Question 8: @Request["Q8"]</div>
    <div>Comments: @Request["Q8Comments"]</div> 
     <div>Question 9: @Request["Q9"]</div>
    <div>Comments: @Request["Q9Comments"]</div> 
     <div>Question 10: @Request["Q10"]</div>
    <div>Comments: @Request["Q10Comments"]</div> 
     <div>Question 11: @Request["Q11"]</div>
    <div>Comments: @Request["Q10Comments"]</div> 
     <div>Question 12: @Request["Q12"]</div>
    <div>Comments: @Request["Q12Comments"]</div> 
     <div>Question 13: @Request["Q13"]</div>
    <div>Comments: @Request["Q13Comments"]</div> 
     <div>Question 14: @Request["Q14"]</div>
    <div>Comments: @Request["Q14Comments"]</div> 
     <div>Question 15: @Request["Q15"]</div>
    <div>Comments: @Request["Q15Comments"]</div> 
     <div>Question 16: @Request["Q16"]</div>
    <div>Comments: @Request["Q16Comments"]</div> 
</div>
 </div>
     var Q1=Request["Q1"];
     var Q1Comments=Request["Q1Comments"];
     var Q2=Request["Q2"];
     var Q2Comments=Request["Q2Comments"];
     var Q3=Request["Q3"];
     var Q3Comments=Request["Q3Comments"];
     var Q4=Request["Q4"];
     var Q4Comments=Request["Q4Comments"];
     var Q5=Request["Q5"];
     var Q5Comments=Request["Q5Comments"];
     var Q6=Request["Q6"];
     var Q6Comments=Request["Q6Comments"];
     var Q7=Request["Q7"];
     var Q7Comments=Request["Q7Comments"]; 
     var Q8=Request["Q8"];
     var Q8Comments=Request["Q8Comments"]; 
     var Q9=Request["Q9"];
     var Q9Comments=Request["Q9Comments"]; 
     var Q10=Request["Q10"];
     var Q10Comments=Request["Q10Comments"];
     var Q11=Request["Q11"];
     var Q11Comments=Request["Q11Comments"];
     var Q12=Request["Q12"];
     var Q12Comments=Request["Q12Comments"];
     var Q13=Request["Q13"];
     var Q13Comments=Request["Q13Comments"];
     var Q14=Request["Q14"];
     var Q14Comments=Request["Q14Comments"];
     var Q15=Request["Q15"];
     var Q15Comments=Request["Q15Comments"]; 
     var Q16=Request["Q16"];
     var Q16Comments=Request["Q16Comments"];
     var SubmitDate=DateTime.Now;
    var ApplicationName=Request["ApplicationName"];
     var WeekNumber=Request["WeekNumber"];
    var FirstName=Request["FirstName"];
     var LastName=Request["LastName"];

    
       var db = Database.Open("CCS");
        db.Execute("INSERT INTO WeekOne (Q1, Q1Comments, Q2, Q2Comments, Q3, Q3Comments, Q4, Q4Comments, Q5, Q5Comments, Q6, Q6Comments, Q7, Q7Comments, Q8, Q8Comments, Q9, Q9Comments, Q10, Q10Comments, Q11, Q11Comments, Q12, Q12Comments, Q13, Q13Comments, Q14, Q14Comments, Q15, Q15Comments, Q16, Q16Comments, SubmitDate, ApplicationName, WeekNumber, FirstName, LastName) VALUES (@0, @1, @2, @3, @4, @5, @6, @7, @8, @9, @10, @11, @12, @13, @14, @15, @16, @17, @18, @19, @20, @21, @22, @23, @24, @25, @26, @27, @28, @29, @30, @31, @32, @33, @34, @34, @35)", Q1, Q1Comments, Q2, Q2Comments, Q3, Q3Comments, Q4, Q4Comments, Q5, Q5Comments, Q6, Q6Comments, Q7, Q7Comments, Q8, Q8Comments, Q9, Q9Comments, Q10, Q10Comments, Q11, Q11Comments, Q12, Q12Comments, Q13, Q13Comments, Q14, Q14Comments, Q15, Q15Comments, Q16, Q16Comments, SubmitDate, ApplicationName, WeekNumber, FirstName, LastName);

     
        
 }else{
     
 
if(Request["FirstName"].IsEmpty()) {
   ModelState.AddError("FirstName", "Please enter your first name!");
    }

if(Request["LastName"].IsEmpty()) {
   ModelState.AddError("LastName", "Please enter your last name!");
 }

if(Request["Q1"].IsEmpty()) {
   ModelState.AddError("Q1", "Please select an answer.");    
}

if(Request["Q1Comments"].Length > 250) {
   ModelState.AddError("Q1Comments", "Sorry, your comments exceeded 250 characters.");    
}


if(Request["Q2"].IsEmpty()) {
   ModelState.AddError("Q2", "Please select an answer.");    
 }    

if(Request["Q2Comments"].Length > 250) {
   ModelState.AddError("Q2Comments", "Sorry, your comments exceeded 250 characters.");    
}


if(Request["Q3"].IsEmpty()) {
   ModelState.AddError("Q3", "Please select an answer.");    
 }   

if(Request["Q3Comments"].Length > 250) {
   ModelState.AddError("Q3Comments", "Sorry, your comments exceeded 250 characters.");    
}


if(Request["Q4"].IsEmpty()) {
   ModelState.AddError("Q4", "Please select an answer.");    
 }   

if(Request["Q4Comments"].Length > 250) {
   ModelState.AddError("Q4Comments", "Sorry, your comments exceeded 250 characters.");    
}


if(Request["Q5"].IsEmpty()) {
   ModelState.AddError("Q5", "Please select an answer.");    
 }   

if(Request["Q5Comments"].Length > 250) {
   ModelState.AddError("Q5Comments", "Sorry, your comments exceeded 250 characters.");    
}


if(Request["Q6"].IsEmpty()) {
   ModelState.AddError("Q6", "Please select an answer.");    
 }   

if(Request["Q6Comments"].Length > 250) {
   ModelState.AddError("Q6Comments", "Sorry, your comments exceeded 250 characters.");    
}


if(Request["Q7"].IsEmpty()) {
   ModelState.AddError("Q7", "Please select an answer.");    
 }   

if(Request["Q7Comments"].Length > 250) {
   ModelState.AddError("Q7Comments", "Sorry, your comments exceeded 250 characters.");    
}


if(Request["Q8"].IsEmpty()) {
   ModelState.AddError("Q8", "Please select an answer.");    
 }   

if(Request["Q8Comments"].Length > 250) {
   ModelState.AddError("Q8Comments", "Sorry, your comments exceeded 250 characters.");    
}


if(Request["Q9"].IsEmpty()) {
   ModelState.AddError("Q9", "Please select an answer.");    
 }   

if(Request["Q9Comments"].Length > 250) {
   ModelState.AddError("Q9Comments", "Sorry, your comments exceeded 250 characters.");    
}


if(Request["Q10"].IsEmpty()) {
   ModelState.AddError("Q10", "Please select an answer.");    
 }   

if(Request["Q10Comments"].Length > 250) {
   ModelState.AddError("Q10Comments", "Sorry, your comments exceeded 250 characters.");    
}


if(Request["Q11"].IsEmpty()) {
   ModelState.AddError("Q11", "Please select an answer.");    
 }   

if(Request["Q11Comments"].Length > 250) {
   ModelState.AddError("Q11Comments", "Sorry, your comments exceeded 250 characters.");    
}


if(Request["Q12"].IsEmpty()) {
   ModelState.AddError("Q12", "Please select an answer.");    
 }   

if(Request["Q12Comments"].Length > 250) {
   ModelState.AddError("Q12Comments", "Sorry, your comments exceeded 250 characters.");    
}


if(Request["Q13"].IsEmpty()) {
   ModelState.AddError("Q13", "Please select an answer.");    
 }   

if(Request["Q13Comments"].Length > 250) {
   ModelState.AddError("Q13Comments", "Sorry, your comments exceeded 250 characters.");    
}


if(Request["Q14"].IsEmpty()) {
   ModelState.AddError("Q14", "Please select an answer.");    
 }   

if(Request["Q14Comments"].Length > 250) {
   ModelState.AddError("Q14Comments", "Sorry, your comments exceeded 250 characters.");    
}


if(Request["Q15"].IsEmpty()) {
   ModelState.AddError("Q15", "Please select an answer.");    
 }   

if(Request["Q15Comments"].Length > 250) {
   ModelState.AddError("Q15Comments", "Sorry, your comments exceeded 250 characters.");    
}


if(Request["Q16"].IsEmpty()) {
   ModelState.AddError("Q16", "Please select an answer.");    
 }   

if(Request["Q16Comments"].Length > 250) {
   ModelState.AddError("Q16Comments", "Sorry, your comments exceeded 250 characters.");    
}



 if(!ModelState.IsValid) {
    ModelState.AddFormError("Please answer all questions and/or fix the errors below before submitting this exam");
    
    
    }else{  

 
        
}
}
}  
   
    
    
 <div align="center">

/*
++++++++++++++++++++++++++++++++++++++++++++++
BODY OF EXAM REMOVED HERE
++++++++++++++++++++++++++++++++++++++++++++++
*/


</div>

<br>
<br>
<div align="center">
<table border="0" cellpadding="3">
<tr>
<td align="center" valign="middle">
<font face="Arial" size="2" color="#000000">
Please enter your first name: <input type="text" size=25 name="FirstName" value="@Request["FirstName"]" /> @Html.ValidationMessage("FirstName")
</td>
 <td rowspan="2" align="left" valign="middle">
<input type="submit" value="Submit" onClick="willReset=confirm('Submit this Exam?');return willReset;">
<input type="reset" value="Clear & Reset" onClick="willReset=confirm('Are you sure you want to Reset?');return willReset;">
<input type="hidden" name="WeekNumber" value="1" />
<input type="hidden" name="ApplicationName" value="CCS Exams Week I" />    
    
 </td>
</tr>
 <tr>    
 <td align="center" valign="middle">
<font face="Arial" size="2" color="#000000">   
 Please enter your last name: <input type="text" size=25 name="LastName" value="@Request["LastName"]" /> @Html.ValidationMessage("LastName")   
</td>
</tr>
</table>
    
</div>
</form>

Last edited by jpjamie; January 11th, 2012 at 02:59 PM..
 
Old January 11th, 2012, 03:34 PM
Imar's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
Default

Hi jpjamie,

Take a look at this:

@32, @33, @34, @34, @35

Number 34 is listed twice. I didn't count them, but I assume 34 is gender which is put in the gender and first name columns. You should probably change this to:

@32, @33, @34, @35, @36

Hope this helps,

Imar
__________________
Imar Spaanjaars
http://Imar.Spaanjaars.Com
Follow me on Twitter

Author of Beginning ASP.NET 4.5 : in C# and VB, Beginning ASP.NET Web Pages with WebMatrix
and Beginning ASP.NET 4 : in C# and VB.
Did this post help you? Click the button below this post to show your appreciation!
 
Old January 11th, 2012, 03:36 PM
Authorized User
 
Join Date: Mar 2011
Posts: 74
Thanks: 21
Thanked 2 Times in 2 Posts
Default FIGURED IT OUT!

Had duplicate column entry for value @34!

See the code below...

Code:
  var db = Database.Open("CCS");
        db.Execute("INSERT INTO WeekOne (Q1, Q1Comments, Q2, Q2Comments, Q3, Q3Comments, Q4, Q4Comments, Q5, Q5Comments, Q6, Q6Comments, Q7, Q7Comments, Q8, Q8Comments, Q9, Q9Comments, Q10, Q10Comments, Q11, Q11Comments, Q12, Q12Comments, Q13, Q13Comments, Q14, Q14Comments, Q15, Q15Comments, Q16, Q16Comments, SubmitDate, ApplicationName, WeekNumber, FirstName, LastName) VALUES (@0, @1, @2, @3, @4, @5, @6, @7, @8, @9, @10, @11, @12, @13, @14, @15, @16, @17, @18, @19, @20, @21, @22, @23, @24, @25, @26, @27, @28, @29, @30, @31, @32, @33, @34, @34, @35)", Q1, Q1Comments, Q2, Q2Comments, Q3, Q3Comments, Q4, Q4Comments, Q5, Q5Comments, Q6, Q6Comments, Q7, Q7Comments, Q8, Q8Comments, Q9, Q9Comments, Q10, Q10Comments, Q11, Q11Comments, Q12, Q12Comments, Q13, Q13Comments, Q14, Q14Comments, Q15, Q15Comments, Q16, Q16Comments, SubmitDate, ApplicationName, WeekNumber, FirstName, LastName);
As usual, something "simple" can cost you hours of searching!
ONWARD!

JJ
 
Old January 11th, 2012, 05:28 PM
Authorized User
 
Join Date: Mar 2011
Posts: 74
Thanks: 21
Thanked 2 Times in 2 Posts
Default

Quote:
Originally Posted by Imar View Post
Hi jpjamie,

Take a look at this:

@32, @33, @34, @34, @35

Number 34 is listed twice. I didn't count them, but I assume 34 is gender which is put in the gender and first name columns. You should probably change this to:

@32, @33, @34, @35, @36

Hope this helps,

Imar
Right on the mark!
I noticed the error shortly after posting and we must have been posting this about the same time! LOL!

Thanks Imar!
 
Old January 11th, 2012, 06:04 PM
Imar's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
Default

You're welcome. Glad to hear it's fixed....

Imar
__________________
Imar Spaanjaars
http://Imar.Spaanjaars.Com
Follow me on Twitter

Author of Beginning ASP.NET 4.5 : in C# and VB, Beginning ASP.NET Web Pages with WebMatrix
and Beginning ASP.NET 4 : in C# and VB.
Did this post help you? Click the button below this post to show your appreciation!





Similar Threads
Thread Thread Starter Forum Replies Last Post
Very Strange issue with a php form Tracysgoingnutsagain Beginning PHP 0 April 11th, 2008 04:44 PM
Strange Upload Issue Elenesski ASP.NET 1.0 and 1.1 Professional 2 April 8th, 2007 11:26 PM
Strange ArrayIndexOutOfBoundsException ISsue kapweb J2EE 0 January 7th, 2006 07:35 PM
Issue with dropdown list and submit - ASP.NET Montenegro ASP.NET 1.0 and 1.1 Basics 0 March 24th, 2004 04:40 PM





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