Hey all, this is kind of a 3 part question/request.

I have a contact form where I want online users to fill in their name, email and message and press submit to send that information to the site admin.

I want to do 3 things with this.

1) I want to check and make sure the user has entered the correct info (i believe I have already done that with field validators.

2) I want the email sent to the site admin (this part works, but it actually sends the email 2x. once with the full info the user entered and the second is a blank email).

3) I want the information from the Name and Email sent to a database (maybe xml or csv file) to pull for email blasts/tracking etc.

Right now, I'm able to check for name, email and message and send the email but not much more and I am not exactly sure how to get an .aspx file to show up as an .html file for web browser viewing.

Now I'm a LONG way from school and don't remember exactly how to do this stuff but i'm sure there's got to be a tutorial or link out there somewhere that goes through this step by step that you guys may know about.

I've also placed my code below for anyone willing to chime in on where I'm going wrong.

Thanks in advance.

Here is the code from my Default.aspx.vb file

Imports System.Net.Mail

Partial Class MasterPage
    Inherits System.Web.UI.MasterPage

    Protected Sub Page_Load(sender As Object, e As EventArgs) Handles Me.Load

    End Sub

    Public Sub ClearForm()
        txtName.Text = String.Empty
        txtEmail.Text = String.Empty
        txtMsg.Text = String.Empty
    End Sub


    Protected Sub btnSubmit_Click(sender As Object, e As EventArgs) Handles btnSubmit.Click

        Dim SmtpServer As New SmtpClient()
        Dim mail As New MailMessage()

        mail = New MailMessage()
        mail.From = New MailAddress("Comments@email.com")
        mail.To.Add("test@gmail.com")
        mail.Subject = "Contact Message"
        mail.Body = "Name: " & txtName.Text & Environment.NewLine & "Email Address: " & txtEmail.Text & Environment.NewLine & "Message: " & txtMsg.Text
        mail.IsBodyHtml = False

        SmtpServer.Send(mail)
        MsgBox("Your Message Has Been Sent")

        ClearForm()

    End Sub
End Class

And then here is my code from the Default.aspx file

<%@ Master Language="VB" CodeFile="MasterPage.master.vb" Inherits="MasterPage" %>

<!DOCTYPE html>

<html xmlns="http://www.w3.org/1999/xhtml">
<head id="Head1" runat="server">
    <title></title>
    <style type="text/css">
        #form1 {
            margin-right: 0px;
        }
    </style>

</head>
    <body id="Body1" style="background-color: rgb(56,55,54); margin-right: 0px;" runat="server">
        <form id="form1" runat="server">
            <div style="height: 572px; width: 1180px;">
                <img src="Contact.png" />
                <div>
                    <asp:TextBox ID="txtName" runat="server" Style="position:absolute; width: 319px; height: 32px; top: 155px; left: 443px;" BorderStyle="None" TabIndex="1"></asp:TextBox>
                    <asp:RequiredFieldValidator ID="txtNameRequiredField" runat="server" ControlToValidate="txtName" Style="position:absolute; top: 175px; left: 612px; width: 153px;" ErrorMessage="Please Enter Your Name." BorderStyle="None" Font-Size="Small"></asp:RequiredFieldValidator>
                </div>
                <div>
                    <asp:TextBox ID="txtEmail" runat="server" Style="position:absolute; width: 319px; height: 32px; top: 252px; left: 443px;" BorderStyle="None" TabIndex="2"></asp:TextBox>
                    <asp:RequiredFieldValidator ID="txtEmailRequiredField" runat="server" ControlToValidate="txtEmail" Style="position:absolute; top: 272px; left: 582px; width: 208px;" ErrorMessage="Please Enter an Email Address." BorderStyle="None" Font-Size="Small"></asp:RequiredFieldValidator>
                    <asp:RegularExpressionValidator ID="RegularExpressionValidator1" runat="server" ControlToValidate="txtEmail" Style="position:absolute; top: 272px; left: 555px; width: 210px;" ErrorMessage="Please Enter A Valid Email Address." ValidationExpression="\w+([-+.']\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*" Font-Size="Small"></asp:RegularExpressionValidator>
                </div>
                <div>
                    <asp:TextBox ID="txtMsg" runat="server" Style="position:absolute; width: 323px; height: 175px; top: 349px; left: 441px;" BorderStyle="None" TabIndex="3" TextMode="MultiLine"></asp:TextBox>
                    <asp:RequiredFieldValidator ID="txtMsgRequiredField" runat="server" ControlToValidate="txtMsg" Style="position:absolute; top: 512px; left: 445px; height: 16px; width: 303px;" ErrorMessage="Please Enter A Message." BorderStyle="None" Font-Size="Small"></asp:RequiredFieldValidator>
                </div>
                <div>
                    <asp:Button ID="btnSubmit" runat="server" onclick="btnSubmit_Click" Style="position:absolute; top: 542px; left: 678px; width: 88px; height: 25px;" Text="Submit" BorderStyle="None" />
                </div>
                <div>
                    <asp:ValidationSummary ID="ValidationSummary1" runat="server" Style="position:absolute; top: 368px; left: 454px; height: 147px; width: 285px;" BorderStyle="None" DisplayMode="List" Visible="False" />
                </div>
            </div>
        </form>
    </body>
</html>

Once again thanks in advance to anyone who can point me in the right direction. I am sure there's got to be a video tutorial of someone doing this. I just can't find it.

Member Avatar for LastMitch

Now I'm a LONG way from school and don't remember exactly how to do this stuff but i'm sure there's got to be a tutorial or link out there somewhere that goes through this step by step that you guys may know about.

@leroy green

I think you need to learn because this code works on a mvc framework

learn "what" exactly? maybe I asked the wrong question but... I'm making this in VS 2012 and wanted to know if there is a tutorial that someone here can link me to that will walk me through what I asked about in my og post.

The code will send but there are some other things that I want to do as well.

I'll try to give you a hand with some of these items but we need to clarify something first.

you indicated that the code above is your default.aspx, but the page directive indicates otherwise. This appears to be your Master page (masterpage.master). Master pages are generally used for create a common layout. You would then create a default.aspx page that selects a master.page.

Maybe you simply just copied/pasted this incorrectly...Can you check on this first before other items are addressed.

yeah, i copied and pasted wrong. sorry. not at home so I can't grab that info but what you see above "sans" the masterpage stuff is what's on my default page.

pretty much what you see here is what's behind the design on my default.aspx page

Ok, lets handle one problem at a time. by the way, it may be more helpful to break up the issues into their own threads, otherwise, there's too much going on...

With regard to #2, sending two emails. The reason is because the button click event is happening two times. In your aspx page, you are specifying a onclick event...

<asp:Button ID="btnSubmit" runat="server" onclick="btnSubmit_Click"

Then in your code behind, you are specifying an event handler for the subroutine.

Protected Sub btnSubmit_Click(sender As Object, e As EventArgs) Handles btnSubmit.Click

It should be one or the other. In VB, i think it would be easier for you to just remove the onclick attribute from the button control, leave your code behind as is.

Work on this, report back...once its fixed, we'll look at the next item.

Member Avatar for LastMitch

I'm making this in VS 2012 and wanted to know if there is a tutorial that someone here can link me to that will walk me through what I asked about in my og post.

@leroy green

Here is the link:

http://www.asp.net/web-pages/overview/getting-started/introducing-razor-syntax-%28vb%29

The code will send but there are some other things that I want to do as well.

Base on the things I read so far, you are pretty much on your own.

You are asking for help but you post a code that you got no clue how to work?

That is not good at all meaning you got no clue how to work on the mvc framework?

Either you post this in the wrong section or you didn't know. This is ASP.net section. I only look at the ASP.net code not the VB code, I'm not familiar with VB at all.

So JorgeM point out somethings already plus explaning it too.

If your intention was to post in VB section.

Then JorgeM would kindly move it to there. =)

@LastMitch
If this is the wrong place I truly apologize and as far as having "no clue," I kind of explained earlier that it's been a LONG time since I've done this and I'm getting back into it so you are right. I don't remember too much... I remember some small things but that's about it.

@JorgeM
Thanks for the insight, I'll turn that around tonight and let you know what's up.

@JorgeM
The change worked like a charm and also made it MUCH snappier (i guess for translating less code). that's a LOT.

good to hear that update.

What else do you have left? Has this following item been resolved by you or do you need further guidance?

I want the information from the Name and Email sent to a database (maybe xml or csv file) to pull for email blasts/tracking etc.

I'd recommend a database file although you can store this information in a file. Do you have access to MSSQL or other database platform? Are you familiar with SQL?

Well now the only thing left is the collection of that info to a db and then throwing it online. I am relatively familiar with mysql (i work with it about 3x a week) but if you recommend a db file. should i just add that on the vb end and furthermore, should I take this part to the vb boards?

I'd suggest MSSQL or MySQL. If you need specific help with VB code and you consider this thread solved, you could move on to a new thread and ask for specific help in that forum category. There are quite a bit of VB gurus monitoing that category.

If its more asp.net related, you can continue in this category. I suspect you'll get help either way.

Okay, if i wanted to create more specificity on a thread just about the database should i just close this and start a new one based solely on database creation from the users entry?

Sure you can do that. Otherwise you'll have a very long thread here talking about many topics

If your question is sql related, post a question in the database category. If its asp.net related, asp.net category is fine.

Okay cool. but question. if i'm using vb to obtain the data and put it into a database.... which one would be best?

post a new thread in asp.net. you should describe the problem and post any relevent code you have. details are important, but be relevant.

no problemo, thanks

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.