📄 formwizard.aspx.cs
字号:
using System;
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;
using Wrox.WebModules.Accounts.Business;
namespace Wrox.WebModules.MailingLists.Web
{
public class FormWizard : Wrox.ThePhile.Web.PhilePage
{
protected System.Web.UI.WebControls.Button Create;
protected System.Web.UI.WebControls.DropDownList ListsDropDown;
protected System.Web.UI.WebControls.CheckBox AllowUnsubscription;
protected System.Web.UI.WebControls.CheckBox AskFirstName;
protected System.Web.UI.WebControls.CheckBox AskLastName;
protected System.Web.UI.WebControls.Table TableResult;
protected System.Web.UI.WebControls.Label ResultForm;
protected System.Web.UI.WebControls.Table TableWizard;
protected System.Web.UI.WebControls.TextBox ResultFormHTML;
protected void Page_Load(object sender, EventArgs e)
{
// check if the current user is allowed to administer lists/subscriptions
if (!Context.User.Identity.IsAuthenticated ||
!((SitePrincipal)Context.User).HasPermission((int)MailingListsPermissions.AdministerData))
{
// if not, redirect to the Login page
Response.Redirect("/ThePhile/Modules/Users/Login.aspx?ShowError=true", true);
}
if (!Page.IsPostBack)
{
// load all the avaible lists in the DropDown control
ListsDropDown.DataSource = Business.List.GetLists().Tables[0].DefaultView;
ListsDropDown.DataBind();
}
}
protected void Create_Click(object sender, EventArgs e)
{
string formHTML="";
// create the subscription controls (table, textbox to type the address, submit button
// and a hidden field to store the destination ListID value)
formHTML += string.Format("<input type=\"hidden\" name=\"ListID\" value=\"{0}\">", ListsDropDown.SelectedItem.Value);
formHTML += "\n<center>\n<table>";
// add the Fist Name choice if the AskFirstName CheckBox is checked
if (AskFirstName.Checked)
{
formHTML += "\n <tr>\n <td colspan=\"2\">";
formHTML += "\n <small>First Name:</small>";
formHTML += "\n </td>\n </tr>";
formHTML += "\n <tr>\n <td colspan=\"2\">";
formHTML += "\n <input type=\"text\" name=\"FirstName\" size=\"30\">";
formHTML += "\n </td>\n </tr>";
}
// add the Fist Name choice if the AskFirstName CheckBox is checked
if (AskLastName.Checked)
{
formHTML += "\n <tr>\n <td colspan=\"2\">";
formHTML += "\n <small>Last Name:</small>";
formHTML += "\n </td>\n </tr>";
formHTML += "\n <tr>\n <td colspan=\"2\">";
formHTML += "\n <input type=\"text\" name=\"LastName\" size=\"30\">";
formHTML += "\n </td>\n </tr>";
}
// add the Email Address field and the Submit button
formHTML += "\n <tr><td><small>Email Address:</small></td></tr>";
formHTML += "\n <tr>\n <td><input type=\"text\" name=\"Email\" size=\"20\"></td>";
formHTML += "\n <td><input type=\"submit\" value=\"Submit\"></td>";
formHTML += "\n </tr>";
// add the Unsubscribe choice if the AllowUnsubscription CheckBox is checked
if (AllowUnsubscription.Checked)
{
formHTML += "\n <tr>\n <td colspan=\"2\">";
formHTML += "\n <small><input type=\"radio\" name=\"Action\" value=\"Subscribe\" checked>Subscribe";
formHTML += "\n <input type=\"radio\" name=\"Action\" value=\"Unsubscribe\">Unsubscribe</small>";
formHTML += "\n </td>\n </tr>";
}
formHTML += "\n</table>\n</center>";
// show the table just created
ResultForm.Text = formHTML;
// get the settings
Configuration.ModuleSettings settings = Configuration.ModuleConfig.GetSettings();
// add the <form> tag and show the HTML code in the TextBox
formHTML = string.Format("<form name=\"newsletter\" action=\"{0}\" method=\"get\">\n{1}\n</form>",
settings.SubscribeUrl, formHTML);
ResultFormHTML.Text = formHTML;
// show the result table and the HTML code
TableResult.Visible=true;
}
#region Web Form Designer generated code
override protected void OnInit(EventArgs e)
{
//
// CODEGEN: This call is required by the ASP.NET Web Form Designer.
//
base.OnInit(e);
InitializeComponent();
}
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
this.Load += new System.EventHandler(this.Page_Load);
}
#endregion
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -