• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 447
  • Last Modified:

ASP.NET - error processing form, sending email

Hello - I'm taking a form that was previously done in ASP that gathers vars, logs them into an Access db and then emails a confirmation along with the data.  The server platform has moved to ASP.NET (which I have no experience with) and I am getting some errors I don't know how to troubleshoot.  

Here's the error:
Compiler Error Message: BC30188: Declaration expected.

Some sample detailed compiler output:
c:\windows\system32\inetsrv> "C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\vbc.exe" /t:library /utf8output /R:"C:\WINDOWS\assembly\GAC_MSIL\System.Configuration\2.0.0.0__b03f5f7f11d50a3a\System.Configuration.dll" /R:"C:\WINDOWS\assembly\GAC_32\System.Web\2.0.0.0__b03f5f7f11d50a3a\System.Web.dll" /R:"C:\WINDOWS\assembly\GAC_MSIL\System\2.0.0.0__b77a5c561934e089\System.dll" /R:"C:\WINDOWS\assembly\GAC_MSIL\System.Xml\2.0.0.0__b77a5c561934e089\System.Xml.dll" /R:"C:\WINDOWS\assembly\GAC_MSIL\System.Drawing\2.0.0.0__b03f5f7f11d50a3a\System.Drawing.dll" /R:"C:\WINDOWS\assembly\GAC_32\System.Data\2.0.0.0__b77a5c561934e089\System.Data.dll" /R:"C:\WINDOWS\assembly\GAC_32\System.EnterpriseServices\2.0.0.0__b03f5f7f11d50a3a\System.EnterpriseServices.dll" /R:"C:\WINDOWS\assembly\GAC_MSIL\System.Web.Services\2.0.0.0__b03f5f7f11d50a3a\System.Web.Services.dll" /R:"C:\WINDOWS\assembly\GAC_MSIL\System.Web.Mobile\2.0.0.0__b03f5f7f11d50a3a\System.Web.Mobile.dll" /out:"C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\Temporary ASP.NET Files\ndir\7aa9b65d\2fb7e58b\App_Web_sgdonetj.dll" /debug- /win32resource:"C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\Temporary ASP.NET Files\ndir\7aa9b65d\2fb7e58b\sgdonetj.res" /define:_MYTYPE=\"Web\" /imports:Microsoft.VisualBasic,System,System.Collections,System.Collections.Specialized,System.Configuration,System.Text,System.Text.RegularExpressions,System.Web,System.Web.Caching,System.Web.SessionState,System.Web.Security,System.Web.Profile,System.Web.UI,System.Web.UI.WebControls,System.Web.UI.WebControls.WebParts,System.Web.UI.HtmlControls  "C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\Temporary ASP.NET Files\ndir\7aa9b65d\2fb7e58b\App_Web_sgdonetj.0.vb" "C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\Temporary ASP.NET Files\ndir\7aa9b65d\2fb7e58b\App_Web_sgdonetj.1.vb" "C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\Temporary ASP.NET Files\ndir\7aa9b65d\2fb7e58b\App_Web_sgdonetj.2.vb"

Microsoft (R) Visual Basic Compiler version 8.0.50727.832
for Microsoft (R) .NET Framework version 2.0.50727.832
Copyright (c) Microsoft Corporation.  All rights reserved.

C:\Inetpub\wwwroot\ndir\process.aspx(331) : error BC30188: Declaration expected.

email = request.form("email")
~~~~~                        
C:\Inetpub\wwwroot\ndir\process.aspx(332) : error BC30188: Declaration expected.

firstname = request.form("firstname")
~~~~~~~~~                            
C:\Inetpub\wwwroot\ndir\process.aspx(333) : error BC30188: Declaration expected.

etc... through all the vars

Here is some of my code:
<%@Language=VBScript%>
<%Response.Buffer = True%>
<%@ import Namespace="System.Web.Mail" %>
<Script Language="VBScript" Runat="Server">

Function check_string(field, low, high, mode, isOpt)

 (lots off validation here of input elements - all goes through fine)

Dim email
Dim firstname
Dim lastname
(etc....lots of vars declared)

email = request.form("email")  //----this is where the errors begin
firstname = request.form("firstname")

What do I need to change here for the previously functioning ASP code to work under ASP.NET? Thanks in advance for explicit code examples.
0
betagirl
Asked:
betagirl
  • 6
  • 4
1 Solution
 
samtran0331Commented:
Try changing this:
<%@Language=VBScript%>
to this:
<%@ Page Language="VB" %>

and giving your variables a type:
Dim email As String
0
 
samtran0331Commented:
also, if you're using ASP.Net 2.0, change this:
<%@ import Namespace="System.Web.Mail" %>
to:
<%@ Import Namespace="System.Net.Mail" %>
0
 
TheNigeCommented:
Why did you change this to run under ASP.Net and not just leave it?

I would suggest converting the code to .Net standard as well.  When you delcare your variables give them a datatype.

Dim email as String
Dim firstname as String
etc.

This is not VBScript anymore - it is VB.Net

0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
betagirlAuthor Commented:
I implemented all of the recommended changes, and still get the same error.  I would have loved to have left it ASP, but the person managing the server....and all the access to and configuration of it...does not support CDO - which is what the mail portion of this previously used. So in changing that, required the .aspx page extension, etc...  

Am I wrong here? You can still use CDO on ASP.NET, right?
0
 
samtran0331Commented:
If I remember right...ASP uses CDONTS.dll for email, ASP.Net use CDOSYS.dll
But in ASP.Net, you don't think in terms of com objects....they have a wrapper for email which is what the "imports System.Net.Mail" does

can you post the full page code?
0
 
betagirlAuthor Commented:
samtran0331 -
I've made some progress.  The form is now validating and getting data into the db, but I'm still having some mail problems.  I've been told to use <%@ import Namespace="System.Net.Mail" %> and it works using the code below, but only if the "to" and "from" are hard coded. I need to pass the email addressess in as variables however, but it doesn't seem to be working (the code below).  Can you tell in the code what I'm doing wrong and why the syntax is not working?  I don't get an error with this code, btw, it appears to go fine, but the email never arrives.  

DOESN'T WORK:
dim emailTo
emailTo = email    ///this value (email) is successfully obtained from the form as before the mail function, it is getting input into the database

       'create the mail message
      Dim mail As New MailMessage()
      
      'set the addresses
      mail.From = New MailAddress("name@address.com")
      mail.To.Add(emailTo)
      
      'set the content
      mail.Subject = emailSubject
       mail.Body = emailBodyText
      mail.IsBodyHtml = false
      
      'send the message
      Dim smtp As New SmtpClient("127.0.0.1")
      try
      smtp.Send(mail)

DOES WORK (email gets sent, but I cannot hard code the value - need it passed in)

dim lblErrMsg
       'create the mail message
      Dim mail As New MailMessage()
      
      'set the addresses
      mail.From = New MailAddress("name@address.com")
      mail.To.Add("name@address.com")
      
      'set the content
      mail.Subject = emailSubject
       mail.Body = emailBodyText
      mail.IsBodyHtml = false
      
      'send the message
      Dim smtp As New SmtpClient("127.0.0.1")
      try
      smtp.Send(mail)

0
 
samtran0331Commented:
I would verify that the email variable and the emailTo variable are indeed there....


dim emailTo as string
emailTo = email    

if emailTo <> "" then

       'create the mail message
      Dim mail As New MailMessage()
     
      'set the addresses
      mail.From = New MailAddress("name@address.com")
      mail.To.Add(emailTo)
     
      'set the content
      mail.Subject = emailSubject
       mail.Body = emailBodyText
      mail.IsBodyHtml = false
     
      'send the message
      Dim smtp As New SmtpClient("127.0.0.1")
      try
      smtp.Send(mail)

else
 Response.Write("Couldn't get emailTo.")
End if





Or if you want to confirm the email did come in...add a quick response.write check...

dim emailTo as string
emailTo = email  

Response.write("The emailTo variable is:  " & emailTo.ToString)

       'create the mail message
      Dim mail As New MailMessage()
     
      'set the addresses
      mail.From = New MailAddress("name@address.com")
      mail.To.Add(emailTo)
     
      'set the content
      mail.Subject = emailSubject
       mail.Body = emailBodyText
      mail.IsBodyHtml = false
     
      'send the message
      Dim smtp As New SmtpClient("127.0.0.1")
      try
      smtp.Send(mail)

0
 
samtran0331Commented:
...also, I'm guessing you're not using Visual Studio or Visiual Web Developer Express?
If not, go get the latter from MS...it's free...and it will make life easier working with .Net...
0
 
betagirlAuthor Commented:
Thanks samtran0331 - the vars were getting through ok, turns out, for some reason, there is a huge delay in when the mail gets sent out.  So all sorted.  I accepted one of your first answer to my original question, as it started me down the path of being able to troubleshoot the rest of the page, in addition to getting the mail settings sorted.  

Ultimately, to get the page to validate properly , I put the top level functions inside:
<Script Language="VB" Runat="Server">
// all functions here
</script>

and then put the form vars collection and validation, db inserts as well as email  inside <% %>

Everything working, just giant delay now in form submission and server sending out the emails.

Thanks for your help!


0
 
samtran0331Commented:
glad you got it working...if you do continue to do ASP.Net ...and don't have Visual Studio 2005...
I would recommend you get Visual Web Dev Express...
http://msdn.microsoft.com/vstudio/express/vwd/

It's free and only does ASP.Net...but you get some powerful stuff like debugging, intellisense, etc.
0
 
betagirlAuthor Commented:
Thanks! I've got an old copy of Visual Studio (not 2005 I don't think) but haven't used it in years. I mostly do PHP these days - it's been over a year since I've touched ASP even (thus really rusty, and dumbfounded by how .NET was handling things).  Should I need to go back to MS web technologies, I'll definitely use a dev tool!
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

  • 6
  • 4
Tackle projects and never again get stuck behind a technical roadblock.
Join Now