Wrox Programmer Forums
Go Back   Wrox Programmer Forums > ASP.NET and ASP > ASP.NET 2.0 > ASP.NET 2.0 Basics
|
ASP.NET 2.0 Basics If you are new to ASP or ASP.NET programming with version 2.0, this is the forum to begin asking questions. Please also see the Visual Web Developer 2005 forum.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the ASP.NET 2.0 Basics section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old September 2nd, 2008, 03:36 PM
Registered User
 
Join Date: Sep 2008
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via AIM to rmullins1
Default asp basics help - namespaces ( I think?)

I've gotten myself into a bigger asp VB coding project than I imagined and I need some help understanding some basics...

What I'm doing is pretty simple -

From a flash widget form with only 3 inputs, I need to do 3 things in ASP:
(1) send an email to me with 3 inputs
(2) send a confirmation email to the User
(3) append the User's Email to a text file (to be loaded into flash later in order to verify a unique email address)

I have working code for the emails, and working code to write to a text file - but I can't merge them into one asp document, I think, because I don't understand how to use the System.IO Namespace.

Here's where I'm having issues:

To write to a text file requires Importing the System.IO namespace, but when I Import that in the same ASP file as my email processing script I start getting a lot of errors in the email script. It seems like the System.IO namespace causes ASP to interpret my code differently. The errors tell me to add Parens where I didn't need them before etc.

So, Is there a way to Isolate the imported Namespace so that it only applies to a select chunk of code instead of the entire page?
Or am I understanding this incorrectly.

Here's my code for writing a text file that I am having trouble merging into another asp document:

/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*

<% @ LANGUAGE="VBSCRIPT" CODEPAGE="1252" %>
<%@ Import Namespace="System.IO" %>

<%
'sending emails happens here
' ...if Mail.SendMail then


Dim recemails As String

    recemails = Request.Form("emailaddress")

    Dim fp As StreamWriter

    Dim myemails = recemails
    Try
        fp = File.CreateText(Server.MapPath("../text/") & "emails.txt")
        fp.WriteLine(myemails)
        fp.Close()
    Catch err As Exception
    Finally
    End Try


Response.Write ("received emails= " & recemails)
Response.Write ("myemails= " & myemails)
%>

/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*

Thanks - Any help is greatly appreciated.
 
Old September 2nd, 2008, 09:08 PM
Friend of Wrox
 
Join Date: Jun 2008
Posts: 1,649
Thanks: 3
Thanked 141 Times in 140 Posts
Default

Ummm....your first line is utterly bogus.

<% @ LANGUAGE="VBSCRIPT" CODEPAGE="1252" %>

You can't use VBScript in ASP.NET. You must use VB or C#.

And although using
    recemails = Request.Form("emailaddress")
isn't technically *wrong* in ASP.NET, it's not normal coding practice.

You seem to have a hodge-podge of old left-over ASP habits hanging on as you venture into the ASP.NET world. I really think you need to go back to the beginning of learning ASP.NET and understanding the enormously different object model it uses, not to mention major syntax differences.

If you are one of those people who got fooled into believing that ASP.NET was just a minor change from ASP... Well, don't feel lonesome; a large part of the world was snookered that way. ASP.NET resembles ASP no more than, say, JSP does. No, maybe less than some JSP pages. Mind you, it's probably all worth it in the long run, but it's a steep learning curve.

May I suggest one thing to make your journey into new worlds harder in the short term but ENORMOUSLY better in the long run: Get in the habit of always using OPTION STRICT ON with VB.NET.
 
Old September 3rd, 2008, 09:24 AM
Registered User
 
Join Date: Sep 2008
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via AIM to rmullins1
Default

Thanks, Old Pedant.

I realize I have very little clue what I'm doing. (I'm coming from an Actionscript background and I'm primarily as web designer - that should explain a lot :)

Either way, I have to make this d*#$ thing work. So, suppose I wanted to continue using VBScript for now until I have time to properly learn vb.net - How can I isolate a namespace to only apply to one chunk of code?

If this is entirely the wrong forum to be posting a VBScript question in let me know and I'll move on, but if someone can help me understand why I can't use that namespace with my mailer code, I would greatly appreciate it. (I'm not asking for free code here, I'm trying to understand concepts)
 
Old September 3rd, 2008, 01:26 PM
Friend of Wrox
 
Join Date: Jun 2008
Posts: 1,649
Thanks: 3
Thanked 141 Times in 140 Posts
Default

(1) VBScript is only used in ASP pages, *NOT* in ASP.NET pages. (Well, it can also be used to script MSIE and in standalone usage, but those are irrelevant to this discussion.)

(2) VBScript doesn't use namespaces. Has no knowledge or understanding of them.

(3) None of the code you show would come close to working in ASP/VBScript.

So, sorry, but you will have to bite the bullet and learn ASP.NET and VB.NET. It's pointless at this time to learn ASP. It's rapidly going the way of the dodo.

As for the namespace: Looks fine to me. But try changing from LANGUAGE="VBSCRIPT" to LANGUAGE="VB". You have other problems, but I can't see that they are related to a namespace issue.
 
Old September 3rd, 2008, 04:42 PM
Registered User
 
Join Date: Sep 2008
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via AIM to rmullins1
Default

Thanks again Old Pedant. I do appreciate your responses.

I'm looking into VB.Net classes at the local community college here ;)





Similar Threads
Thread Thread Starter Forum Replies Last Post
Need some help on basics jagan7 Java Basics 3 September 9th, 2007 02:44 AM
Basics Andy122 Dreamweaver (all versions) 3 January 2nd, 2005 03:36 PM
Basics required for ASP gsvirdi Classic ASP Basics 3 November 22nd, 2004 06:32 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.