Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > ASP.NET and ASP > Other ASP.NET > BOOK: Beginning ASP.NET Web Pages with WebMatrix
Password Reminder
Register
Register | FAQ | Members List | Calendar | 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 tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developersí questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Display Modes
  #1 (permalink)  
Old July 22nd, 2014, 04: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 04:30 PM.
Reply With Quote
  #2 (permalink)  
Old July 22nd, 2014, 04:42 PM
Imar's Avatar
Wrox Author
Points: 71,164, Level: 100
Points: 71,164, Level: 100 Points: 71,164, Level: 100 Points: 71,164, Level: 100
Activity: 100%
Activity: 100% Activity: 100% Activity: 100%
 
Join Date: Jun 2003
Location: Utrecht, Netherlands.
Posts: 16,960
Thanks: 79
Thanked 1,559 Times in 1,536 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!
Reply With Quote
The Following User Says Thank You to Imar For This Useful Post:
jpjamie (July 22nd, 2014)
  #3 (permalink)  
Old July 22nd, 2014, 07: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!
Reply With Quote
  #4 (permalink)  
Old July 28th, 2014, 01: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!
Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off

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 02: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 02: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



All times are GMT -4. The time now is 03:36 PM.


Powered by vBulletin®
Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.