?? addredirect.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;
namespace ASPNET.StarterKit.Communities.Admin.CustomRedirects
{
/// <summary>
/// Summary description for AddRedirect.
/// </summary>
public class AddRedirect : System.Web.UI.Page
{
protected System.Web.UI.WebControls.TextBox txtDestinationUrl;
protected System.Web.UI.WebControls.RequiredFieldValidator RequiredFieldValidator2;
protected System.Web.UI.WebControls.Label lblFormatErrorText;
protected System.Web.UI.WebControls.Label lblDestinationError;
protected System.Web.UI.WebControls.RadioButton rbSourceExact;
protected System.Web.UI.WebControls.RadioButton rbSourcePath;
protected System.Web.UI.WebControls.RadioButton rbDestExact;
protected System.Web.UI.WebControls.Button btnEdit;
protected System.Web.UI.WebControls.TextBox txtSourceUrl;
protected System.Web.UI.WebControls.RequiredFieldValidator RequiredFieldValidator1;
protected System.Web.UI.WebControls.Label lblSourceError;
protected System.Web.UI.WebControls.Button btnAdd;
protected System.Web.UI.WebControls.RadioButton rbDestPath;
private void Page_Load(object sender, System.EventArgs e)
{
// Put user code to initialize the page here
}
#region Web Form Designer generated code
override protected void OnInit(EventArgs e)
{
//
// CODEGEN: This call is required by the ASP.NET Web Form Designer.
//
InitializeComponent();
base.OnInit(e);
}
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
this.rbSourceExact.CheckedChanged += new System.EventHandler(this.rbSourceExact_CheckedChanged);
this.rbSourcePath.CheckedChanged += new System.EventHandler(this.rbSourcePath_CheckedChanged);
this.btnAdd.Click += new System.EventHandler(this.btnAdd_Click);
this.Load += new System.EventHandler(this.Page_Load);
}
#endregion
private void btnAdd_Click(object sender, System.EventArgs e)
{
if (Page.IsValid)
{
lblFormatErrorText.Text = "";
CustomRedirectInfo NewRedirect = new CustomRedirectInfo(txtSourceUrl.Text,txtDestinationUrl.Text,rbSourcePath.Checked,rbDestPath.Checked);
if(!NewRedirect.IsValidSource)
{
lblFormatErrorText.Visible = true;
lblFormatErrorText.Text += "Source Invalid: " + NewRedirect.SourceValidationErrorMessage + "<br>";
lblSourceError.Visible = true;
}
else
{
lblFormatErrorText.Visible = false;
lblSourceError.Visible = false;
}
if(!NewRedirect.IsValidDestination)
{
lblFormatErrorText.Visible = true;
lblFormatErrorText.Text += "Invalid Destination: " + NewRedirect.DestinationValidationErrorMessage + "<br>";
lblDestinationError.Visible = true;
}
else
{
lblFormatErrorText.Visible = false;
lblDestinationError.Visible = false;
}
if(NewRedirect.IsValidRedirect)
{
bool success = CustomRedirectUtility.AddRedirect(NewRedirect);
if(!success)
{
lblFormatErrorText.Visible = true;
lblFormatErrorText.Text = "A Redirect for this source URL already exists";
lblSourceError.Visible = true;
return;
}
Response.Redirect("Default.aspx");
}
}
}
private void rbSourceExact_CheckedChanged(object sender, System.EventArgs e)
{
rbDestExact.Enabled = true;
rbDestExact.Checked = true;
rbDestPath.Checked = false;
rbDestPath.Enabled = false;
}
private void rbSourcePath_CheckedChanged(object sender, System.EventArgs e)
{
rbDestExact.Enabled = true;
rbDestPath.Enabled = true;
}
}
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -