摘要:【ASP.NET】Form傳遞方式
a.aspx
<%@ Page Language="C#" validateRequest="false" AutoEventWireup="true" CodeFile="mail.aspx.cs" Inherits="mail" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
<style type="text/css">
#TextArea1
{
height: 134px;
width: 330px;
}
</style>
</head>
<body>
<form runat="server">
<div>
<asp:Label ID="Label1" runat="server" Text="Email"></asp:Label>
<input id="email" type="text" runat="server" name="email" />
<asp:RequiredFieldValidator
ID="RequiredFieldValidator1"
runat="server"
ErrorMessage="請輸入Email"
ValidationGroup="submit01"
ControlToValidate="email">
</asp:RequiredFieldValidator><br />
<asp:Label ID="Label3" runat="server" Text="PWD"></asp:Label>
<input id="pwd" name="pwd" type="password" runat="server" />
<asp:RequiredFieldValidator
ID="RequiredFieldValidator2"
runat="server"
ErrorMessage="請輸入PWD"
ValidationGroup="submit01"
ControlToValidate="pwd">
</asp:RequiredFieldValidator><br />
<asp:Label ID="Label2" runat="server" Text="Cont"></asp:Label>
<textarea id="mail_cont" name="mail_cont" runat="server"></textarea><br />
<br />
<asp:Button ID="Button1" runat="server" Text="send" ValidationGroup="submit01"
onclick="Button1_Click" />
<br />
</div>
</form>
</body>
</html>
a.aspx.cs
using System;
using System.Collections.Generic;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Net.Mail;
public partial class mail : System.Web.UI.Page
{
string Email;
string Mail_cont = "無內容";
string Pwd;
protected void Page_Load(object sender, EventArgs e)
{
}
protected void Button1_Click(object sender, EventArgs e)
{
if (IsPostBack)
{
Email = Request.Form["email"];
Mail_cont = Request.Form["mail_cont"];
Mail_cont = HttpUtility.HtmlEncode(Mail_cont);
Pwd = Request.Form["pwd"];
}
else
{
Email = Request.QueryString["email"];
Mail_cont = Request.QueryString["mail_cont"];
Mail_cont = HttpUtility.HtmlEncode(Mail_cont);
Pwd = Request.QueryString["pwd"];
}
Response.Write("Email=" + Email + "<BR>");
Response.Write("Pwd=" + Pwd + "<BR>");
Response.Write("cont=" + Mail_cont + "<BR>");
}
}