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 October 31st, 2012, 01:08 AM
Authorized User
 
Join Date: Jun 2012
Posts: 45
Thanks: 11
Thanked 0 Times in 0 Posts
Smile Classifieds: delete routine error

Hey Guys,
I added my own delete routine to the Classifieds tutorial.

Oddly, it deletes new records differently than old records(?). My delete routine has a delete button and then a final CONFIRMation prompt. It seems to bypass the confirm prompt for only my new records(?). I don't know if it's a CACHE issue or something else.

Thanks for Looking AND your Great Books,
Edgy in Mesquite

*** my Delete Button: ************
<p><input type="submit" name="buttonDelete" value="Delete Item"
onclick="return confirm('Confirm:\nDelete this Item from Ads\n @title')" />

*** Delete Code snippet **********
if(IsPost && !Request["buttonDelete"].IsEmpty()){
itemId = Request.Form["itemId"];
var db = Database.Open("Classifieds");
var deleteCommand = "DELETE FROM Items WHERE ID = @0";

WebCache.Remove("cachedData");
db.Execute(deleteCommand, itemId);
Response.Redirect("~/Admin/Items");
**********************************************


******** the Complete Delete.cshtnl Code ************
Code:
@{ 
    Page.Title = "Delete Ad";
    var itemId = "";  
    var title = ""; 
    var description = ""; 
    var price = 0m;    
    var categoryId = 0;
    var datePosted = "";
    var duration = 0;
    var condition = "";
    var confirmLne = "Confirm: \n Delete This Item \n@title";
    

    if(!IsPost){ 
        if(!Request.QueryString["id"].IsEmpty() && Request.QueryString["id"].IsInt()){ 
            itemId = Request.QueryString["id"]; 
            var db = Database.Open("Classifieds"); 
            var dbCommand = "SELECT * FROM Items WHERE Id = @0"; 
            var row = db.QuerySingle(dbCommand,itemId); 
            if(row != null) { 
                title = row.Title; 
                description = row.Description; 
                price = row.Price;
                categoryId = row.CategoryId;
                condition = row.Condition;
                datePosted = row.DatePosted.ToString("D");
                //category = row.Category;
                //itemId = row.Id;


            } 
            else{ 
           Validation.AddFormError("No Classified AD was found for that ID.");
             } 
        } 
        else{ 
      Validation.AddFormError("No Classified Ad was found for that ID."); 
        } 
    } 

    if(IsPost && !Request["buttonDelete"].IsEmpty()){ 
        itemId = Request.Form["itemId"]; 
        var db = Database.Open("Classifieds"); 
        var deleteCommand = "DELETE FROM Items WHERE ID = @0"; 
        
        WebCache.Remove("cachedData");
        db.Execute(deleteCommand, itemId); 
        Response.Redirect("~/Admin/Items"); 
    } 
}
<html>
    <head>
        <title>Delete an Item</title>
    </head>
    <body>
        <h1>Delete an Item</h1>
        @Html.ValidationSummary()
        @*<p><a href="~/Admin/EditItems">Return to Items listing</a></p>*@

        <form method="post">
            <fieldset>
                <legend>Item Information</legend>

                <p><span>Title:</span>
                    <span>@title</span></p>

                <p><span>Description:</span>
                    <span>@description</span></p>

                <p><span>Price:</span>
                    <span>@price.ToString("c")</span></p>

                <p><span>Condition:</span>
                    <span>@condition</span></p>

                <p><span>Date Posted:</span>
                    <span>@datePosted</span></p>

                <input type="hidden" name="itemId" value="@itemId" />

                <p><input type="submit" name="buttonDelete" value="Delete Item"
                        onclick="return confirm('Confirm:\nDelete this Item from Ads\n @title')" />
                 <input type="button" value="Cancel" name="Cancel" onclick="window.location.href='Items.cshtml'; return false;" /></p>
            </fieldset>
            <p><a href="~/Admin/Items">Return to Items listing</a></p>
        </form>
    </body>
</html>
 
Old October 31st, 2012, 04:09 AM
Wrox Author
 
Join Date: Dec 2011
Posts: 57
Thanks: 1
Thanked 19 Times in 19 Posts
Default

I can' see any errors or anything in the code you posted that would cause the behaviour you describe.
The Following User Says Thank You to Mike Brind For This Useful Post:
EDGY (October 31st, 2012)
 
Old October 31st, 2012, 11:45 AM
Authorized User
 
Join Date: Jun 2012
Posts: 45
Thanks: 11
Thanked 0 Times in 0 Posts
Smile Unknown behavior with Razor Code

ok, Mike, thanks for Looking...

I was using IE, so I tried Chrome, same result.

Finally, I went back and DELETED the last line in the confirm prompt message;
" \n@title " and the odd behavior disappeared. Don't know why it only affected new records but it did, really. So, I believe there's some kinda bug there, might be RAZOR, or the double lines maybe...or maybe I had an erroneous space "\n @title",...

<input type="submit" name="buttonDelete" value="Delete Item"
onclick="return confirm('Confirm:\nDelete this Item from Ads \n@title')" />

Any new record get the Confirm prompt now, but without the title field anymore...

Thanks,
everything else working real fine...
Edgy in Mesquite
 
Old October 31st, 2012, 11:51 AM
Authorized User
 
Join Date: Jun 2012
Posts: 45
Thanks: 11
Thanked 0 Times in 0 Posts
Smile ? test unknown behavior

Mike ,
If you or Imar want to see this odd behavior out of Professional Curiousity I can give you access to my site. Its just your tutorial, not prod of any type.
would take just a moment to see, no problem

thanks,
Edgy
 
Old November 2nd, 2012, 09:32 PM
Authorized User
 
Join Date: Jun 2012
Posts: 45
Thanks: 11
Thanked 0 Times in 0 Posts
Smile Delete routine/odd Razor behavior: Resolved

Mike , Imar,

This post/thread may be deleted if you guys decide it doesn't add anything of value to the forum discussion. I will test it more later. I deleted the questionable part and have moved on. I'll try it again later after I've gained more experience and knowledge.

Thanks for alll your help,
Edgy in Dallas
 
Old November 3rd, 2012, 08:41 AM
Imar's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
Default

Neither of us has admin rights on this forum, so we can't delete messages.

Also, this:

Quote:
So, I believe there's some kinda bug there, might be RAZOR, or the double lines maybe...or maybe I had an erroneous space "\n @title",...
makes it difficult for us to see what's going on, let alone suggest a fix.

I would look at the resulting HTML / JavaScript in the browser when using this code; I think your code somehow ends up broken, causing the confirm to never be triggered.

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!





Similar Threads
Thread Thread Starter Forum Replies Last Post
Unable to delete file System.IO.Delete error maricar C# 13 March 14th, 2014 06:50 AM
Classifieds tutorial Web Deploy error EDGY BOOK: Beginning ASP.NET Web Pages with WebMatrix 3 October 30th, 2012 11:33 PM
error in .vbs FTP routine invoked from VB 6.0 dgr7 VBScript 0 February 7th, 2007 05:29 PM
File copy routine error! Janet C++ Programming 3 March 13th, 2004 02:41 PM





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