post html to asp.net page for validation and emailing

Discussion in 'ASP .Net' started by csteacy@gmail.com, Jul 20, 2007.

  1. Guest

    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 = ""
    Message.To.Add("", "")
    Message.Bcc.Add("", "")
    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.
    , Jul 20, 2007
    #1
    1. Advertising

  2. <> wrote in message
    news:...

    > 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#...


    --
    Mark Rae
    ASP.NET MVP
    http://www.markrae.net
    Mark Rae [MVP], Jul 20, 2007
    #2
    1. Advertising

  3. Guest

    On Jul 20, 2:09 pm, "Mark Rae [MVP]" <> wrote:
    > <> wrote in message
    >
    > news:...
    >
    > > 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#...
    >
    > --
    > 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.
    , Jul 20, 2007
    #3
  4. <> wrote in message
    news:...

    > 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...?


    --
    Mark Rae
    ASP.NET MVP
    http://www.markrae.net
    Mark Rae [MVP], Jul 20, 2007
    #4
  5. 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/
    ======================================
    <> wrote in message news:...
    > On Jul 20, 2:09 pm, "Mark Rae [MVP]" <> wrote:
    >> <> wrote in message
    >>
    >> news:...
    >>
    >> > 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#...
    >>
    >> --
    >> 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.
    >
    Juan T. Llibre, Jul 20, 2007
    #5
  6. Guest

    On Jul 20, 2:34 pm, "Juan T. Llibre" <>
    wrote:
    > 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/
    > ======================================
    >
    > <> wrote in messagenews:...
    > > On Jul 20, 2:09 pm, "Mark Rae [MVP]" <> wrote:
    > >> <> wrote in message

    >
    > >>news:...

    >
    > >> > 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#...

    >
    > >> --
    > >> 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.


    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.
    , Jul 21, 2007
    #6
  7. Brandon Gano Guest

    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.


    <> wrote in message
    news:...
    > 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 = ""
    > Message.To.Add("", "")
    > Message.Bcc.Add("", "")
    > 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.
    >
    Brandon Gano, Jul 21, 2007
    #7
  8. Guest

    On Jul 21, 11:22 am, "Brandon Gano" <> wrote:
    > 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.


    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.
    , Jul 23, 2007
    #8
  9. Brandon Gano Guest

    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.


    <> wrote in message
    news:...
    > On Jul 21, 11:22 am, "Brandon Gano" <> wrote:
    >> 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.

    >
    > 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, Jul 23, 2007
    #9
  10. Guest

    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 = ""
    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
    , Jul 24, 2007
    #10
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Farooq Khan

    emailing in ASP.NET

    Farooq Khan, Dec 29, 2003, in forum: ASP .Net
    Replies:
    4
    Views:
    829
    Farooq Khan
    Dec 30, 2003
  2. =?Utf-8?B?TWlrZSBNb29yZQ==?=

    Emailing From Asp.net

    =?Utf-8?B?TWlrZSBNb29yZQ==?=, Jul 29, 2004, in forum: ASP .Net
    Replies:
    4
    Views:
    396
    Jim Cheshire [MSFT]
    Sep 30, 2004
  3. wmburns
    Replies:
    5
    Views:
    687
    wayne
    Feb 12, 2006
  4. tshad
    Replies:
    2
    Views:
    321
    tshad
    May 19, 2006
  5. Porky

    ASP Page emailing text file

    Porky, Dec 1, 2003, in forum: ASP General
    Replies:
    6
    Views:
    167
    Aaron Bertrand [MVP]
    Dec 2, 2003
Loading...

Share This Page