|
 |
aspdotnet_website_programming thread: Simple ASP.NET Form
Message #1 by "Rob Furman" <Rob_Furman@h...> on Sun, 2 Jun 2002 15:47:08
|
|
I am very new to ASP.NET (or even ASP for that matter). I want to add a
feedback form on my website. I found some sample code on the Internet,
and I've uploaded it to Brinkster. There are two files: join.aspx and
join.aspx.cs Below is the code for the two files (afterwards scroll down,
as I will tell more about the problem):
join.aspx
--------------------------------------------------------
<%@ Page language="c#" Codebehind="join.aspx.cs" AutoEventWireup="false"
Inherits="ASPAlliance.Pages.join" Src="join.aspx.cs"
Trace="false" Debug="false" %>
<%@ Register TagPrefix="SSTemplate" tagname="showHeader"
src="/controls/showHeader.ascx"%>
<%@ Register TagPrefix="SSTemplate" tagname="showFooter"
src="/controls/showFooter.ascx"%>
<SSTemplate:showHeader id="header" title="Become a Columnist"
runat="server" />
<form method="post" runat="server">
<br>
<b>Become an ASPAlliance Columnist!</b>
<P>
If you think you would make a valuable addition to the ASP Alliance as a
columnist, please fill out the form below. In the box provided, please
copy and
paste a complete article that you would post on your column. This article
will
be reviewed by our columnists. If we accept it, you will become an
ASPAlliance
columnist.
</P>
<P>
<B>This is not just free web space! You must be willing to publish quality
articles
related to ASP, .NET, or other Internet technologies.</B></P>
<P>
<B>ASPAlliance lets you retain ownership and copyright of all of your
material!</B>You
can submit it to other sites, publish it in articles, and basically do
whatever
you want with it. However, ASPAlliance will keep unmodified copies of your
articles indefinitely as a service to our readers.
</P>
<P>
Some of the benefits of being an AspAlliance.com columnist include free
web
hosting with ASP and ASP.NET support, SQL Server access (SQL2000), and a
POP3
mail account, if desired. You're welcome to promote yourself as an author
or
developer or whatever you like, provided that your column provides value
to
AspAlliance visitors as well. Columnists are encouraged to display ads on
their
sites, which help support the site and provide modest royalties to the
columnists. Also, all columnist sites must include a reference to the
ASPAlliance, and by publishing material on this site, you grant
ASPAlliance.com
the right to host such material indefinitely, regardless of whether or not
you
remain a member/columnist (as noted above).
</P>
<table border="1" bordercolor="red" cellspacing="0" cellpadding="2">
<tr>
<td width="336">
Full Name
</td>
<td>
<asp:textbox id="fullname" runat="Server"></asp:textbox>
</td>
<td>
<asp:requiredfieldvalidator id="fullname_required" runat="Server"
controltovalidate="fullname" errormessage="Full name is
required."></asp:requiredfieldvalidator>
</td>
</tr>
<tr>
<td width="336">
How long have you been developing dynamic Internet applications?
</td>
<td>
<asp:dropdownlist id="howlong" runat="Server">
<asp:listitem value=""></asp:listitem>
<asp:listitem value="Just Starting"></asp:listitem>
<asp:listitem value="1-3 Months"></asp:listitem>
<asp:listitem value="4-6 Months"></asp:listitem>
<asp:listitem value="6-12 Months"></asp:listitem>
<asp:listitem value="Over a Year"></asp:listitem>
<asp:listitem value="Too Long ;) "></asp:listitem>
</asp:dropdownlist>
</td>
<td>
<asp:requiredfieldvalidator id="howlong_required" runat="Server"
controltovalidate="howlong" errormessage="Please select an item from the
list."></asp:requiredfieldvalidator>
</td>
</tr>
<tr>
<td width="336">
Email
</td>
<td>
<asp:textbox id="email" runat="server" width="150"></asp:textbox>
</td>
<td>
<asp:requiredfieldvalidator id="email_required" runat="Server"
controltovalidate="email" errormessage="Email is
required."></asp:requiredfieldvalidator>
</td>
</tr>
<tr>
<td width="336">
<P>Requested Username / Folder name<br>
This is used both for your login to the site and as your folder name, e.g.
www.aspalliance.com/folder/. This will also be used as your
POP3 account, if you request one.
</P>
</td>
<td>
<asp:textbox id="username" runat="server" width="150"></asp:textbox>
</td>
<td>
<asp:requiredfieldvalidator id="username_required" runat="Server"
controltovalidate="username" errormessage="A username/foldername is
required."></asp:requiredfieldvalidator>
</td>
</tr>
<tr>
<td width="336">
Requested POP Account (username@a...)
</td>
<td>
<asp:dropdownlist id="pop_requested" runat="Server">
<asp:listitem value=""></asp:listitem>
<asp:listitem value="No, I don't need a POP account."></asp:listitem>
<asp:listitem value="Yes, please give me a POP account."></asp:listitem>
</asp:dropdownlist>
</td>
<td>
<asp:requiredfieldvalidator id="pop_requested_required" runat="Server"
controltovalidate="pop_requested" errormessage="You must select Yes
or No."></asp:requiredfieldvalidator>
</td>
</tr>
<tr>
<td width="336">
Requested Access Method
</td>
<td>
<asp:listbox id="access" runat="Server" selectionmode="Multiple">
<asp:ListItem Value="FTP">FTP</asp:ListItem>
<asp:ListItem Value="Frontpage Server Extensions (FPSE)">Frontpage Server
Extensions
(FPSE)</asp:ListItem>
</asp:listbox>
</td>
<td>
<asp:requiredfieldvalidator id="access_required" runat="Server"
controltovalidate="access" errormessage="Please select at least one access
method."></asp:requiredfieldvalidator>
</td>
</tr>
<tr>
<td width="336">
Sample Article
</td>
<td>
<asp:textbox id="sample" runat="Server" textmode="MultiLine" rows="10"
columns="60"></asp:textbox>
</td>
<td>
<asp:requiredfieldvalidator id="sample_required" runat="Server"
controltovalidate="sample" errormessage="A sample article is
required."></asp:requiredfieldvalidator>
</td>
</tr>
</table>
<asp:button id="btnSubmit" text="Send" runat="Server"></asp:button>
<p>
How does this page work? Click <a
href="http://www.aspalliance.com/stevesmith/articles/how_join.asp">
here</a> to see!
</p>
</form>
<SSTemplate:showFooter id="footer" runat="server" />
--------------------------------------------------------
join.aspx.cs
--------------------------------------------------------
namespace ASPAlliance.Pages
{
using System;
using System.Web.Mail;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Web;
using System.Web.SessionState;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;
/// <summary>
/// Summary description for join.
/// </summary>
public class join : System.Web.UI.Page
{
protected System.Web.UI.WebControls.Button btnSubmit;
protected System.Web.UI.WebControls.RequiredFieldValidator sample_required;
protected System.Web.UI.WebControls.TextBox sample;
protected System.Web.UI.WebControls.RequiredFieldValidator access_required;
protected System.Web.UI.WebControls.ListBox access;
protected System.Web.UI.WebControls.RequiredFieldValidator
pop_requested_required;
protected System.Web.UI.WebControls.DropDownList pop_requested;
protected System.Web.UI.WebControls.RequiredFieldValidator
username_required;
protected System.Web.UI.WebControls.TextBox username;
protected System.Web.UI.WebControls.RequiredFieldValidator email_required;
protected System.Web.UI.WebControls.TextBox email;
protected System.Web.UI.WebControls.RequiredFieldValidator
howlong_required;
protected System.Web.UI.WebControls.DropDownList howlong;
protected System.Web.UI.WebControls.RequiredFieldValidator
fullname_required;
protected System.Web.UI.WebControls.TextBox fullname;
public join()
{
Page.Init += new System.EventHandler(Page_Init);
}
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
//
// Evals true first time browser hits the page
//
}
}
protected void Page_Init(object sender, EventArgs e)
{
//
// CODEGEN: This call is required by the ASP+ Windows Form Designer.
//
InitializeComponent();
}
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
this.btnSubmit.Click += new System.EventHandler(this.btnSubmit_Click);
this.Load += new System.EventHandler(this.Page_Load);
}
public void btnSubmit_Click (object sender, System.EventArgs e)
{
String message="";
String access_methods="";
int i;
if (Page.IsValid) {
Trace.Write("Submit", "Page is valid -- send email.");
message += "Full Name: " + fullname.Text + "\n";
message += "How Long?: " + howlong.SelectedItem.Text + "\n";
message += "Email: " + email.Text + "\n";
message += "Request POP Account?: " + pop_requested.SelectedItem.Text
+ "\n";
message += "Requested Username / Web name / POP3 Account(if requested): "
+ username.Text + "\n";
message += "Requested Access Method(s): ";
for (i=0;i<access.Items.Count;i++) {
if(access.Items[i].Selected) {
if (access_methods!="") {
access_methods+=", ";
}
access_methods += access.Items[i].Text;
}
}
message += access_methods + "\n";
message += "Sample Article: \n" + sample.Text;
MailMessage Mailer = new MailMessage();
Mailer.From = email.Text;
Mailer.To = "columnist-join@a...";
Mailer.Subject = "ASPAlliance Join Request";
Mailer.Body = message;
SmtpMail.SmtpServer = "localhost";
SmtpMail.Send(Mailer);
Server.Transfer("jointhankyou.aspx");
// Response.Redirect("jointhankyou.aspx");
}
}
}
}
--------------------------------------------------------
At first I was getting the following error message:
Server Error in '/' Application.
Parser Error
Description: An error occurred during the parsing of a resource required
to service this request. Please review the following specific parse error
details and modify your source file appropriately.
Parser Error Message: Could not load type 'ASPAlliance.Pages.join'.
Source Error:
Line 1: <%@ Page language="c#" Codebehind="join.aspx.cs"
AutoEventWireup="false" Inherits="ASPAlliance.Pages.join" Trace="false"
Debug="false" %>
Line 2: <%@ Register TagPrefix="SSTemplate" tagname="showHeader"
src="/controls/showHeader.ascx"%>
Line 3: <%@ Register TagPrefix="SSTemplate" tagname="showFooter"
src="/controls/showFooter.ascx"%>
Source File: \\genfs2\www23\strongcrayon\join.aspx Line: 1
I "fixed" this error, I think, by adding the Src="join.aspx.cs" to the
join.aspx file. Was this a good idea? Anyway, I now have a different
error. Now, when I go to join.aspx in my web browser it says the
following:
Compilation Error
Description: An error occurred during the compilation of a resource
required to service this request. Please review the following specific
error details and modify your source code appropriately.
Compiler Error Message: CS2001: Source file '\\genfs2\www23
\strongcrayon\join.aspx.cs' could not be found
Source Error:
[No relevant source lines]
Source File: Line: 0
Actually, I usually get Brinkster error messages when I try to upload the
two files. For example, the following appears sometimes in uploading
join.aspx:
Active Server Pages error 'ASP 0241'
CreateObject Exception
/FileManagerUploadFiles.asp
The CreateObject of '(null)' caused exception C0000005.
Server object error 'ASP 0177 : c0000005'
Server.CreateObject Failed
/FileManagerUploadFiles.asp, line 24
c0000005
But, if I try multiple times it eventually lets me upload the files. And
that's what I have done.
Any help would be greatly appreciated. ~Rob
Message #2 by "Mike Gale" <info@d...> on Mon, 3 Jun 2002 08:59:07 +1200
|
|
I recommend establishing how it works on your own web server BEFORE
uploading to a live site.
I assume you are using Visual Studio. (This product has great tools,
but you should make sure you understand how they work before getting in
too deep.)
You first message indicates that the code behind *.cs file was not
compiled to MSIL. (The compiled file shows as a *.dll in your \bin
directory, there are tools to inspect what is inside the DLL that come
with VS.) Your insertion of a Src attribute told the system to compile
on the fly rather than look for a pre-compiled dll in \bin.
Your second exception message says that it couldn't find the code behind
file to compile. (Inspect your upload directory, using ftp or whatever
and I guess you'll find that no file was uploaded!)
I guess there are some good sites explaining this, though I haven't
checked them for a long time. Try msdn.microsoft.com and
www.gotdotnet.com for a start.
Mike Gale, Decision Engineering (NZ) Ltd.
PS. .NET is a huge system which you can't learn overnight. Take your
time and tackle is steadily and surely.
|
|
 |