直接贴代码了:
/// <summary>
/// 基页面
/// </summary>
public class PageBase : System.Web.UI.Page
{
/// <summary>
/// 显示消息
/// </summary>
/// <param name="message">消息文本</param>
protected virtual void ShowMessage(string message)
{
ShowScript("alert(\"" + FilterInvalidJavascriptKeyword(message) + "\");");
}
/// <summary>
/// 提供系统全局显示脚本
/// </summary>
/// <param name="javascript">要显示的脚本,无须再添加脚本头标记 < javascript type="text/javascript" ></param>
protected virtual void ShowScript(string javascript)
{
ClientScript.RegisterStartupScript(this.GetType(), "sysInfo", javascript, true);
}
/// <summary>
/// 过滤非法的 Javascript 字符,方法不完整,会继续修改
/// </summary>
/// <param name="word">需要过滤的字符串</param>
/// <returns></returns>
private static string FilterInvalidJavascriptKeyword(string word)
{
return word.Replace("\"", "\\\"");
}
}
/// <summary>
/// 添加/修改页面的基类
/// </summary>
/// <typeparam name="T"></typeparam>
public class PageSave<T> : PageBase where T : class,new()
{
/// <summary>
/// 当前页面是否处于编辑状态
/// </summary>
protected bool IsEdit
{
get;
set;
}
private T _model;
/// <summary>
/// 处于编辑状态的模型
/// </summary>
protected T Model
{
set
{
if(!IsEdit)
{
throw new NotSupportedException("设置 Model 失败,该属性只能用于编辑状态,即 IsEdit = ture 是才可以赋值!");
}
_model = value;
}
get
{
if (!IsEdit)
{
throw new NotSupportedException("获取 Model 失败,该属性只能用于编辑状态,即 IsEdit = ture 是才可以获取!");
}
return _model;
}
}
}
public partial class category_save : PageSave<category>
{
}
谢谢浏览!