Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > ASP.NET and ASP > ASP.NET 2.0 > ASP.NET 2.0 Basics
Password Reminder
Register
| FAQ | Members List | Search | Today's Posts | Mark Forums Read
ASP.NET 2.0 Basics If you are new to ASP or ASP.NET programming with version 2.0, this is the forum to begin asking questions. Please also see the Visual Web Developer 2005 forum.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the ASP.NET 2.0 Basics 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 Search this Thread Display Modes
  #1 (permalink)  
Old September 8th, 2006, 09:58 PM
Registered User
 
Join Date: Sep 2006
Location: Sturgeon Bay, Wisconsin, .
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
Default Email Form - Question from a Newbie

I'm really, really new to programming in ASP.NET 2.0 (just got the book last night). I have a form page built in ASP.NET 2.0 with validators and am working on making the form collect the data and email it.

I've found a tutorial that explains it: http://aspnet101.com/aspnet101/tutorials.aspx?id=14

But I'm not sure where to put the sub doEmail code. When I put it below the label it just appears like text and not like code.

Can anyone out there help explain?

I need to get my form to email it's results. Thank you.

~ Morgan Mann
http://www.1designsource.com
Reply With Quote
  #2 (permalink)  
Old September 13th, 2006, 08:09 AM
Authorized User
 
Join Date: Sep 2006
Location: Bangalore, Karnataka, India.
Posts: 19
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Hi Morgan let me help you with this. Assuming you are using Visual Studio or atleast the express edition for editing the .aspx pages. When you add the button in the aspx page, you will find that Visual Studio (VS) will show two tabs down, Design and Source tabs. What you need to do is be in the design mode and double click on the button.

when you do this, you will get the code file .aspx.vb or .aspx.cs (if C#) with the button_click event ie using the sample's button name you would get btnEmail_click. The confusion is in the name, what the user has done is named the button_click as doEmail instead of btnEmail_click. So what you can do is copy the code from the doEmail function and dump it in the btnEmail_click function body.

Now run the form and am sure your form will work :)
Reply With Quote
  #3 (permalink)  
Old September 13th, 2006, 08:58 AM
Registered User
 
Join Date: Sep 2006
Location: Sturgeon Bay, Wisconsin, .
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Thanks for the help!!

I put in the things like you said and I changed my ID to match the IDs in the new code, but I still come up with an error, and I don't know how to redirect the page to another page once it is submitted.
Reply With Quote
  #4 (permalink)  
Old September 13th, 2006, 10:52 AM
Wrox Author
Points: 13,255, Level: 49
Points: 13,255, Level: 49 Points: 13,255, Level: 49 Points: 13,255, Level: 49
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Oct 2005
Location: Ohio, USA
Posts: 4,104
Thanks: 1
Thanked 64 Times in 64 Posts
Send a message via AIM to dparsons
Default

For these lines to work:

Line 23: SmtpMail.SmtpServer = "mail.goquestrealty.com"
Line 24: SmtpMail.Send(objEmail)

At the top of your page you have to do: (I assume you are using Visual Studio)

Imports System.Web.Mail

Then everything should execute just fine. After you call SmtpMail.Send(objEmail) you can do Response.Redirect("./somepage.aspx") to send the user to a new page.

"The one language all programmers understand is profanity."
Reply With Quote
  #5 (permalink)  
Old September 13th, 2006, 12:48 PM
Registered User
 
Join Date: Sep 2006
Location: Sturgeon Bay, Wisconsin, .
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
Default

I'm not sure where to put the code:
Imports System.Web.Mail

Here's my page from the top to the Title tag.

<%@ Page Language="VB" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<script runat="server">
    Protected Sub btnSubmit_Click(ByVal sender As Object, ByVal e As System.EventArgs)
        Dim sMsg As String
        sMsg += "Hi there - here's the information I entered in the form." & vbCrLf
        sMsg += "Name : " & txtName.Text & vbCrLf
        sMsg += "Phone : " & txtPhone.Text & vbCrLf
        sMsg += "Email : " & txtEmail.Text & vbCrLf
        sMsg += "Comments : " & txtComments.Text & vbCrLf

        Dim objEmail As New Mail.MailMessage
        objEmail.To = txtEmail.text
        objEmail.BCC = "" '<--- this would be where you can send it to yourself at the same time.
        objEmail.FROM = ""
        objEmail.SUBJECT = "Here's the subject of the email"
        objEmail.BODY = sMsg
        SmtpMail.SmtpServer = ""
        SmtpMail.Send(objEmail)
        Response.Redirect("")
    End Sub
</script>

<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>Quest Realty - Contact Us</title>
Reply With Quote
  #6 (permalink)  
Old September 13th, 2006, 12:50 PM
Wrox Author
Points: 13,255, Level: 49
Points: 13,255, Level: 49 Points: 13,255, Level: 49 Points: 13,255, Level: 49
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Oct 2005
Location: Ohio, USA
Posts: 4,104
Thanks: 1
Thanked 64 Times in 64 Posts
Send a message via AIM to dparsons
Default

Oh you are using a text editor, underneath <%@ Page Language="VB" %>
add this line:

<%@Import Namespace="System.Web.Mail"%>

"The one language all programmers understand is profanity."
Reply With Quote
  #7 (permalink)  
Old September 13th, 2006, 01:31 PM
Registered User
 
Join Date: Sep 2006
Location: Sturgeon Bay, Wisconsin, .
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
Default

YES!!!!! It works!

Thank you all for your amazing help!

When I'm under less stress I'll have to learn more about ASP.NET 2.0. It's a very handy programming language. Glad I found this forum!

Reply With Quote
  #8 (permalink)  
Old September 13th, 2006, 02:00 PM
Wrox Author
Points: 13,255, Level: 49
Points: 13,255, Level: 49 Points: 13,255, Level: 49 Points: 13,255, Level: 49
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Oct 2005
Location: Ohio, USA
Posts: 4,104
Thanks: 1
Thanked 64 Times in 64 Posts
Send a message via AIM to dparsons
Default

Glad it worked out for you.

"The one language all programmers understand is profanity."
Reply With Quote
  #9 (permalink)  
Old September 13th, 2006, 03:58 PM
Registered User
 
Join Date: Sep 2006
Location: Sturgeon Bay, Wisconsin, .
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Okay. One victory, one defeat.

I tried doing the same code for another page I'm working on for the same site and I'm getting errors whether I put in the Checkbox info at the top or not. Can you guys help?!

Here's a link to the page without any of the stuff in the JavaScript tag up top and it works, once I put the Dim info it cuts out.
Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
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
Newbie question peterh Classic ASP Databases 3 January 17th, 2008 12:25 PM
newbie question pbb Ajax 0 September 26th, 2006 05:47 AM
C# Newbie Question jazzcatone ASP.NET 2.0 Basics 1 May 25th, 2006 10:18 PM
newbie question Warbird XML 0 May 11th, 2005 08:41 AM
Newbie question Beginner VB.NET 2002/2003 Basics 2 November 9th, 2003 07:58 AM



All times are GMT -4. The time now is 08:01 AM.


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