Help on contact page

  • Thread starter Thread starter dgow
  • Start date Start date
D

dgow

I designed a "contact_us" page in visual web developer 2005 express along
with EW2 after viewing tutorials on asp.net's help page. Features work like
they should, but I cannot figure out how to send contact info to email or
data base when the "send" button is pressed. I've watched the tutorials over
& over again. I just can't get it.
Link: http://www.syfloristonline.zipa.com/contact_us.aspx.
Need help
 
Have you ever used the database features of ASP.NET before (ADO.NET and the
System.Data namespace)? If you have, then you basically just need to do that
same type of thing in the Click event of your send button. If you want the
info sent as an email, take a look at the System.Net and System.Net.Mail
namespace. Some of the classes you are likely to use are MailAddress,
SmtpClient, and MailMessage. I'm sure there are many basic examples out
there, so look for one of the examples (videos may help sometimes, but
seeing a complete code example is sometimes better, since that's what you
want to learn how to do) and see if that helps.
 
I've never used the database features yet, but I am going to try and see what
I can do. I'm still trying to learn it as quick as possible. If I see it once
I usually I get it, but there is something I'm missing. I'll keep trying.
Thanks
 
I felt the same way when I first started learning .NET (They didn't teach us
much in the one course I took). But a book that I bought, which probably
tought me more than any other individual resource, is:

ASP.NET 2.0 Unleashed by Stephen Walther
http://www.informit.com/store/product.aspx?isbn=0672328232

There are versions of the book for the other versions of ASP.NET as well,
but one of the most wonderful things about the author is that the book is
example-oriented with complete examples. The author completely explains
every example, and the code comes on a CD in both VB.NET and C#. I think the
example-oriented style will help you a lot, it definitely helped me.
 
I am lost. I cannot find info on what to do next on my web page. I have the
form completed on the contact us page, but have no idea how to connect to the
database or send the form to an email. I feel stupid. Can it be this hard?
 
To connect to a database, do something like the following:

Include the following in your Web.config:

<configuration>
<appSettings>
<add key="connectionstring" value="YOUR CONNECTION STRING"/>
</appSettings>
</configuration>

Use something similar to the following to submit to the database:

Dim myconnection As New
System.Data.OleDb.OleDbConnection(System.Configuration.ConfigurationManager.AppSettings("connectionstring"))
Dim cmdsubmit As New OleDbCommand("YOUR SQL STATEMENT", myconnection)
myconnection.Open()
cmdsubmit.ExecuteNonQuery()
myconnection.Close()


To send an email:

Include the following in your Web.config:

<configuration>
<appSettings>
<add key="smtpserver" value="YOUR SMTP SERVER"/> 'For example,
"smtp.yourdomain.com"
</appSettings>
</configuration>

Dim toaddress As New MailAddress("(e-mail address removed)", "Nathan
Sokalski")
Dim fromaddress As New MailAddress("(e-mail address removed)", "Nathan
Sokalski")
Dim commentsender As New
SmtpClient(System.Configuration.ConfigurationManager.AppSettings("smtpserver"))
commentsender.Credentials = New NetworkCredential("", "") 'This line may or
may not be necessary, ask your Webhost or network administrator
Dim commentmsg As New MailMessage(fromaddress, toaddress)
commentmsg.IsBodyHtml = False
commentMsg.Subject = "YOUR EMAIL SUBJECT"
commentMsg.Body = "YOUR MESSAGE BODY"
commentsender.Send(commentMsg)


If either of these do not work, look at the error messages to help determine
the reason. The reason (if there is one) is most likely due to server
configuration. If you have problems, post your code and the error, we may be
able to help you more with that info. Good Luck!
 
I have no idea where to add this code in the web config. Here is what I have
so far.

<?xml version="1.0"?>
<!--
Note: As an alternative to hand editing this file you can use the
web admin tool to configure settings for your application. Use
the Website->Asp.Net Configuration option in Visual Studio.
A full list of settings and comments can be found in
machine.config.comments usually located in
\Windows\Microsoft.Net\Framework\v2.x\Config
-->
<configuration>
<appSettings/>
<connectionStrings>
<add name="ConnectionString" connectionString="Data
Source=.\SQLEXPRESS;AttachDbFilename=|DataDirectory|\syours.mdf;Integrated
Security=True;User Instance=True"
providerName="System.Data.SqlClient" />
</connectionStrings>
<system.web>


<!--
Set compilation debug="true" to insert debugging
symbols into the compiled page. Because this
affects performance, set this value to true only
during development.

Visual Basic options:
Set strict="true" to disallow all data type conversions
where data loss can occur.
Set explicit="true" to force declaration of all variables.
-->
<compilation debug="true" strict="false" explicit="true"/>
<pages>
<namespaces>
<clear/>
<add namespace="System"/>
<add namespace="System.Collections"/>
<add namespace="System.Collections.Specialized"/>
<add namespace="System.Configuration"/>
<add namespace="System.Text"/>
<add namespace="System.Text.RegularExpressions"/>
<add namespace="System.Web"/>
<add namespace="System.Web.Caching"/>
<add namespace="System.Web.SessionState"/>
<add namespace="System.Web.Security"/>
<add namespace="System.Web.Profile"/>
<add namespace="System.Web.UI"/>
<add namespace="System.Web.UI.WebControls"/>
<add namespace="System.Web.UI.WebControls.WebParts"/>
<add namespace="System.Web.UI.HtmlControls"/>
</namespaces>
</pages>
<!--
The <authentication> section enables configuration
of the security authentication mode used by
ASP.NET to identify an incoming user.
-->
<authentication mode="Forms" />
<!--
The <customErrors> section enables configuration
of what to do if/when an unhandled error occurs
during the execution of a request. Specifically,
it enables developers to configure html error pages
to be displayed in place of a error stack trace.

<customErrors mode="RemoteOnly"
defaultRedirect="GenericErrorPage.htm">
<error statusCode="403" redirect="NoAccess.htm" />
<error statusCode="404" redirect="FileNotFound.htm" />
</customErrors>
-->
</system.web>
</configuration>
 
Change <appSettings/> to the following:

<appSettings>
<add key="connectionstring" value="YOUR CONNECTION STRING"/>
</appSettings>

If you prefer to use the <connectionStrings> element for your
connectionstrings, it looks like you already know how to do that (just make
sure you correctly modify the code I gave you if you do that). You need to
remember that in XML (which is actually what a *.config file is) <tagname/>
is equivelant to <tagname></tagname>.
 
Still VERY VERY lost. I didn't add "connectionstring" It was just there. I
have no idea how the web config did any of that. All I want to do is send
info from a form to an email. Why is this so hard to figure out? Am I that
stupid?
 
What do you have in your Web.config in the <appSettings></appSettings>
element? You should have an <add/> element that specifies your SMTP server.
Why don't you post exactly what you have in this part of your Web.config, as
well as the code you currently have that you are trying to use to send the
email. If you are recieving an error (any error at all) when running this
code, let me know that as well. This will help me narrow down the problem.
Also, make sure you have the necessary permissions to send an email from the
specified SMTP server and check with the administrator of the SMTP server as
to what you may need for the Credentials property.
 
Thats strange, I can send mail through smtp just fine but my email settings
are in <System.Net.Mail> section in web.config.
 
The way I am doing it is not necessarily the only way, so there may be other
ways that involve placing more in the Web.config than I did. I simply use
the technique I do because it is simple, short, and allows me to send an
email with any format I can create the content for. But if an example or
instructions you find on another website use a different technique, don't be
extremely surprised, because there are very few things in .NET (or any
language/framework) that can only be done one way.
 
Right. I wasn't really saying that I was surprised that it was done that
way. I was just saying that I have never seen it like that and all the
Microsoft help says to do is put that stuff in System.Net.Mail and off you
go.
 
Back
Top