Wrox Programmer Forums
| Search | Today's Posts | Mark Forums Read
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 22nd, 2014, 03:28 PM
Authorized User
Points: 313, Level: 6
Points: 313, Level: 6 Points: 313, Level: 6 Points: 313, Level: 6
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Mar 2011
Posts: 74
Thanks: 21
Thanked 2 Times in 2 Posts
Default Passing Database Row Id Using WebMail

Mike or Imar:

I am trying to pass a database row Id in an email, so the user can see the entire contents of the row (online exam results) in page named Final_Results.cshtml.

The user gets an email when a student submits an exam. The email code runs just fine and but was a challenge this morning!

I figured out how to send the user to another page (listing all the exams) but I want also to provide the option for the user to link exam results for the (specific) student who just submitted the exam in the email.

So far I have not been able to pass the database Id to the Final_Results.cshtml using the code below. I think my problem is in the URL syntax of passing the row ID. I've done this before with ColdFusion using CFMAIL, but this seems more of a challenge!

Thanks ahead of time!


Code:
@{   

  var postId = Request["Id"].AsInt(0);
  
  var db = Database.Open("CCS") ;     
  var post = db.QuerySingle("SELECT * FROM FinalExtExam WHERE Id = @0;", postId);
  
  if(post == null)  {
    <div>Sorry, that post was not found!</div>
}else{
  
    var FirstName = post.FirstName;
    var LastName = post.LastName;
    var customerEmail = "jamieson.james@MyInstitution.edu"; 
    var AdminEmail = "Smith.Bob@MyInstitution.edu";
    var debuggingFlag = false;
  
        // Initialize WebMail helper
        WebMail.SmtpServer = "smtprelay.MyInstitution.edu";
        WebMail.SmtpPort = 25;
        WebMail.UserName = "jj42";
        WebMail.Password = "Celtic";
        WebMail.From = "jamieson.james@MyInstitution.edu";

        // Send email;
        WebMail.Send(to: customerEmail, 
            subject: "New CCS Exam Submitted by Dr. " + LastName,
            body: "A CCS Final Exam was just <a href='http://localhost:30053/Final_Results.cshtml?Id=postId'>submitted</a> by Dr. " +  LastName
                         
        );

    }
  
 }

Last edited by jpjamie; July 22nd, 2014 at 03:30 PM..
 
Old July 22nd, 2014, 03:42 PM
Imar's Avatar
Wrox Author
Points: 70,322, Level: 100
Points: 70,322, Level: 100 Points: 70,322, Level: 100 Points: 70,322, Level: 100
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2003
Location: Utrecht, Netherlands.
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
Default

Hi there,

If I understand you correctly, you should be able to just concatenate the Post ID like you do with the last name. Something like this should work:

body: "A CCS Final Exam was just <a href='http://localhost:30053/Final_Results.cshtml?Id=" + postId + "'>submitted</a> by Dr. " + LastName

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!
The Following User Says Thank You to Imar For This Useful Post:
jpjamie (July 22nd, 2014)
 
Old July 22nd, 2014, 06:58 PM
Authorized User
Points: 313, Level: 6
Points: 313, Level: 6 Points: 313, Level: 6 Points: 313, Level: 6
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Mar 2011
Posts: 74
Thanks: 21
Thanked 2 Times in 2 Posts
Default THANKS!

I am now off work for a few days, will try ASAP when get back to work (in a week) but may VPN in and try this!
 
Old July 28th, 2014, 12:28 PM
Authorized User
Points: 313, Level: 6
Points: 313, Level: 6 Points: 313, Level: 6 Points: 313, Level: 6
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Mar 2011
Posts: 74
Thanks: 21
Thanked 2 Times in 2 Posts
Default BIG THANKS IMAR!

The code you helped me with above worked perfectly! I worked a lot these past few days on another "project" and just got back to this. The concatenation compared to ColdFusion is just a wee bit more complex, but it works!




Similar Threads
Thread Thread Starter Forum Replies Last Post
I need help on making an entire grid row selectable and passing id thru a querystring ysfkay ASP.NET 3.5 Basics 2 July 19th, 2010 01:24 PM
$data[0][$row->parentid]['children'][$row->id] = $row->name mehdymahmood BOOK: Professional CodeIgniter ISBN: 978-0-470-28245-8 1 February 2nd, 2010 02:19 AM
html table row id myself.panku ASP.NET 1.x and 2.0 Application Design 0 April 17th, 2008 01:56 PM
show columns with same ID in the same row yuvalk SQL Server 2005 4 February 2nd, 2007 07:46 PM
Creating a Unique ID for each row maxworlund SQL Server DTS 1 March 8th, 2005 09:33 PM





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