Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > ASP.NET and ASP > ASP.NET 2.0 > ASP.NET 2.0 Basics
Password Reminder
| FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
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 tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old February 4th, 2007, 12:45 AM
Authorized User
Points: 195, Level: 3
Points: 195, Level: 3 Points: 195, Level: 3 Points: 195, Level: 3
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
Join Date: Oct 2006
Location: , , .
Posts: 42
Thanks: 3
Thanked 0 Times in 0 Posts
Default Running a Javascript form in ASP.NET:problem


I'm a stupid newbie trying to insert a quick-and-dirty Javascript email form in an .aspx page. For some reason, trying to execute the form returns a "Object reference not set to an instance of an object" error. Will the Javascript only work in a regular .html page, or can ASP.NET controls and Javascript play well together?

Any help or advice would be much appreciated. For reference, the javascript inserted is:

script name="JavaScript">
                    <!-- Copyright 2000 by William Bontrager
                    function SendEmail()
                        var toaddy = 'email@email.net';
                        var subject = 'ATTN: Request Information';
                        var mailer = 'mailto:' + toaddy + '?subject=' + subject +     '&body=' + 
                    'Name%20is\n\t' + document.jsform.visitorname.value + 
                        '\n\n' + 
                    'Email%20is\n\t' + document.jsform.email.value + 
                        '\n\n' + 
                    'Message:\n\n' + document.jsform.message.value +
                        parent.location = mailer;
                     } // -->

<form name="jsform">
                                            <td align="right">Name</td>
                                            <td><input name="visitorname"  size="27"></td>
                                            <td align="right">E-mail</td>
                                            <td><input name="email" size="27"></td>
                        <td colspan="2">
                                            Your message:<br>
                                            <textarea name="message" cols="31" rows="10" wrap="soft">
                                                    <input type="submit" onClick="SendEmail()" value="Send Message">

Reply With Quote
  #2 (permalink)  
Old February 4th, 2007, 05:45 AM
Imar's Avatar
Wrox Author
Points: 72,073, Level: 100
Points: 72,073, Level: 100 Points: 72,073, Level: 100 Points: 72,073, Level: 100
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
Join Date: Jun 2003
Location: Utrecht, Netherlands.
Posts: 17,089
Thanks: 80
Thanked 1,587 Times in 1,563 Posts

Hi there,

I am not sure what you're trying to do, but there are a few problems with your code. First, look at this:

<form name="jsform">

If you look in the HTML in the browser, there's a fair chance that ASP.NET renamed your form to something else. By default, you only have one form, and .NET takes care if it. The final HTML in the browser may shed some light on this.

Second, your form elements may have been renamed, so visitorname is no longer visitorname. Again, look in the HTML for this.

Then the onsubmit. Your function is fired, but the form is also submitted to te server. Not sure if that's what you find.

Finally, look at this:

 parent.location = mailer;

Are you working with frames??

If you explain what your code is supposed to do, I may be able to help you with a .NET alternative....

Imar Spaanjaars
Everyone is unique, except for me.
Author of ASP.NET 2.0 Instant Results and Beginning Dreamweaver MX / MX 2004
Want to be my colleague? Then check out this post.
Reply With Quote
  #3 (permalink)  
Old February 5th, 2007, 09:01 PM
Authorized User
Points: 239, Level: 4
Points: 239, Level: 4 Points: 239, Level: 4 Points: 239, Level: 4
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
Join Date: Jul 2005
Location: , , .
Posts: 43
Thanks: 0
Thanked 0 Times in 0 Posts

I personally haven't had much experience using javascript to send an email so obviously I'm biased but I would perhaps suggest using VB or C# to send your email. There are lots of examples out there on how to do it. Plus Imar is correct. Lots of things get renamed so doing it with the .NET framework will help you get around some of your issues. Just a suggestion. - Jason

Reply With Quote

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
Javascript problem in asp.net sen321x .NET Framework 2.0 1 October 31st, 2007 09:33 PM
Error while running javascript code in ASP.NET Pag fozia_izhar ASP.NET 1.0 and 1.1 Professional 2 December 20th, 2006 03:39 AM
ASP.NET Running and Installation Problem param99 ASP.NET 1.0 and 1.1 Professional 1 November 6th, 2006 03:04 AM
Problem in running ASP.Net 2.0 exstream ASP.NET 2.0 Professional 0 April 26th, 2006 08:48 AM
Problem running app with ASP.NET akhilvira ASP.NET 1.0 and 1.1 Basics 1 January 14th, 2005 09:53 AM

All times are GMT -4. The time now is 01:09 PM.

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