Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / ASP.NET / General / July 2007

Tip: Looking for answers? Try searching our database.

post html to asp.net page for validation and emailing

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
csteacy@gmail.com - 20 Jul 2007 17:15 GMT
Hello,
I am pretty new to asp.net and I've been trying to figure out how to
take a static HTML web form data and send it to an asp.net page to
validate 1 field and then if it passes the validation, create an e-
mail message using jmail and send it to the specified e-mail address.
I've tried using an if then else statement but am really lost in the
coding.  I've added some code below to give an idea of what I'm trying
for the asp.net page:

<%@Page Language="VB" validateRequest="false" %>
<%@Import Namespace="Dimac.JMail" %>
<html>
<title>validate</title>
<body bgcolor="#FFFFFF">
<%
Dim validate

   Validate = Trim(Request.Form("validate"))
' Check the message field for input if is blank
' then add to the display message
   If validate() = "" Then
       Response.Redirect("notsent.html")

       ' If all seems ok begin processing the email
   Else
       Sub Page_Load( ByVal sender As Object, Byval e As EventArgs )
   Dim obj As New Message()
   Message.From.Email = "test@test.com"
   Message.To.Add("email@email1.com", "")
   Message.Bcc.Add("email@email1.com", "")
   Message.Subject = "form subject"
   Message.BodyText = "Phone: " & Request.Form("txtphone")

   Try
       Smtp.Send(Message, "smtpserver")
       Response.Redirect("submitted.html")

   Catch ex As Exception

   End Try
End Sub
   End If%>
</body>
   </html>

I'm posting the HTML page to the asp.net page but with no results.
Could someone point me in the right direction?  Thank you in advance
for your help.
Mark Rae [MVP] - 20 Jul 2007 20:09 GMT
> I'm posting the HTML page to the asp.net page but with no results.
> Could someone point me in the right direction?  Thank you in advance
> for your help.

There's no need to have a separate HTML page...

1) Place your form fields in an aspx page

2) Add an <asp:Button> webcontrol

3) Either use Validation controls or roll your own client-side JavaScript or
server-side VB.NET / C#...

Signature

Mark Rae
ASP.NET MVP
http://www.markrae.net

csteacy@gmail.com - 20 Jul 2007 20:15 GMT
> <cste...@gmail.com> wrote in message
>
[quoted text clipped - 16 lines]
> Mark Rae
> ASP.NET MVPhttp://www.markrae.net

Thank you for your response to this.  I wish I could not use an HTML
page for this but I have to because of the content management system
that we have.  It does HTML forms but not any function with the forms
so I have to set the form to go to different page that can validate
and e-mail the form.  I can't add in Javascript or anything to the
HTML page because it's inside the content management system.  I've
tried to take the page and make it an asp.net page but then I cannot
get the same design.  Is there another option?  Thank you again.
Mark Rae [MVP] - 20 Jul 2007 20:29 GMT
> Thank you for your response to this.  I wish I could not use an HTML
> page for this but I have to because of the content management system
> that we have.  It does HTML forms but not any function with the forms
> so I have to set the form to go to different page that can validate
> and e-mail the form.  I can't add in Javascript or anything to the
> HTML page because it's inside the content management system.

You didn't mention *any* of the above in your original post - we can only
work with the information you provide... :-)

> I've tried to take the page and make it an asp.net page but then I cannot
> get the same design.

That doesn't make sense - an aspx page is nothing more than HTML (and
JavaScript) once it's rendered to the client browser...

What is providing the HTML page's design...?

Signature

Mark Rae
ASP.NET MVP
http://www.markrae.net

Juan T. Llibre - 20 Jul 2007 20:34 GMT
re:
!> I wish I could not use an HTML page for this but I have to
!> because of the content management system that we have.
!> Is there another option?

Sure there is: change your content management system.

Clearly, it's hampering the development of your websites.

Juan T. Llibre, asp.net MVP
asp.net faq : http://asp.net.do/faq/
foros de asp.net, en español : http://asp.net.do/foros/
======================================
>> <cste...@gmail.com> wrote in message
>>
[quoted text clipped - 25 lines]
> tried to take the page and make it an asp.net page but then I cannot
> get the same design.  Is there another option?  Thank you again.
csteacy@gmail.com - 21 Jul 2007 03:59 GMT
> re:
> !> I wish I could not use an HTML page for this but I have to
[quoted text clipped - 40 lines]
> > tried to take the page and make it an asp.net page but then I cannot
> > get the same design.  Is there another option?  Thank you again.

Thank you for your responses.  The plan is in the works to move to a
new CMS soon because of limitations such as this.  But for now
development must still proceed as business proceeds.  Thank you again.
Brandon Gano - 21 Jul 2007 17:22 GMT
It looks like the problem is in your syntax (unless the code got jumbled
when you posted). Are you using Visual Studio to create the processing page?
If so, have you tried compiling the page to see if any errors come up?

The most obvious problem with the code you posted is that you have code
outside of a Sub and the Sub is illegally nested inside an If statement. Try
to move this line:

 Sub Page_Load( ByVal sender As Object, Byval e As EventArgs )

Immediately after the <% and move this line:

 End Sub

Immediately before the %> (after End If). If that doesn't fix your problem,
and the page compiles in VS, please reply with more specific information
about the problem.

> Hello,
> I am pretty new to asp.net and I've been trying to figure out how to
[quoted text clipped - 44 lines]
> Could someone point me in the right direction?  Thank you in advance
> for your help.
csteacy@gmail.com - 23 Jul 2007 20:59 GMT
> It looks like the problem is in your syntax (unless the code got jumbled
> when you posted). Are you using Visual Studio to create the processing page?
[quoted text clipped - 13 lines]
> and the page compiles in VS, please reply with more specific information
> about the problem.

Thank you very much for your suggestion, I made this switch and I have
two errors that come up in VS -

1) Statement cannot appear within a method body.  End of method
assumed. (highlights Sub)

2) End Sub must be preceded by a matching Sub. (highlights End Sub).

I'm not sure what these mean but I'm looking into it.
Please let me know if you have more insight into this.
Thank you for all the help.
Brandon Gano - 23 Jul 2007 23:03 GMT
I would need to see more of the code in order to diagnose the problem. It
looks like you have a Sub within a Sub, which is not allowed.

>> It looks like the problem is in your syntax (unless the code got jumbled
>> when you posted). Are you using Visual Studio to create the processing
[quoted text clipped - 28 lines]
> Please let me know if you have more insight into this.
> Thank you for all the help.
csteacy@gmail.com - 24 Jul 2007 20:13 GMT
I figured this out, thanks to the help from here and some more cut/
paste/think/try etc.  Here's the final code for those also in need of
it in the future.
Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs)

       Dim validate
       validate = (Request.Form("validate").ToString())

       If validate = "159" Then

           ' If all seems ok begin processing the email

           Dim message As New Message()
           message.From.Email = "test@test.com"
           message.Subject = "Form Name"
           message.BodyText = "Name: " & Request.Form("name")

           Try
               Smtp.Send(message, "smtpserver")
               Response.Redirect("submitted.html")

           Catch ex As Exception

           End Try
       Else
           Response.Redirect("notsent.html")
       End If
   End Sub

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.