1. Response.Write("<script>alert('保存成功!');window.location.href='blogReview.aspx?id=1&ulid=30';</script>");
2. ?blogtype='默认分类'&disptype='按类别列出'&id=1
上面如果写成
?blogtype=默认分类&disptype=按类别列出&id=1
那么如果有页面根据Request.QueryString["id"]得到ID的值,会提示错误,解决办法,给字符加上引号
或者写成
?id=1&blogtype=默认分类&disptype=按类别列出
3. String.Format解决sql2000中top后不能带参数的问题(select top @size)
默认显示 数量10篇的日志 显示“查看更多日志”
选择类别 显示类别下所有日志
选择日期 显示当月所有日志
4. 日期中文转换
<%#DataBinder.Eval(Container.DataItem, "Date", "{0:yyyy年MM月dd日}")%> - 2008年04月18日
<%#DataBinder.Eval(Container.DataItem, "Date", "{0:t}")%> - 20:23
<%#DataBinder.Eval(Container.DataItem, "Date","{0:yyyy年MM月dd日tt}"+"{0:t}")%> - 2008年04月18日下午20:23
显示为:2008年04月11日下午21:34
5. 绑定页面Title <%= title%> .cs代码文件中只要给title值就可以自动绑了,不用this.DataBind()
Page.Title = "";
6. 编辑器使用注意事项
1)EnableEventValidation="false"
2)ValidateRequest = "false"
7. 执行带参数的SQL语句后,别忘记cmd.Parameters.Clear()
8. eWebEditor取消部分功能代码:
分行代码:<tr><td><div class=yToolbar><DIV CLASS=TBHandle></DIV>
<DIV CLASS=Btn TITLE='"+lang["Flash"]+"' onclick=\"showDialog('flash.htm', true)\"><IMG CLASS=Ico SRC='buttonimage/blue/flash.gif'></DIV>
<DIV CLASS=Btn TITLE='"+lang["Media"]+"' onclick=\"showDialog('media.htm', true)\"><IMG CLASS=Ico SRC='buttonimage/blue/media.gif'></DIV>
<DIV CLASS=Btn TITLE='"+lang["File"]+"' onclick=\"showDialog('file.htm', true)\"><IMG CLASS=Ico SRC='buttonimage/blue/file.gif'></DIV>
<textarea style="display:none" name="content1"><%=sContent%></textarea>
<iframe id="eWebEditor1" src="../eWebEditor.jsp?id=content1&style=standard" frameborder="0" scrolling="no" width="650" height="350"></iframe>
9. 得到动态添加的下拉框列表选中项的内容 Request["ddlBlogSort"].ToString().Trim()
10. 判断登陆状态"放在Page_PreInit中判断,Page_Load()中不用再去判断了"
为了防止浏览器缓存,使用户B可以编辑用户A的日志,必须添加
// 日掉缓存
Response.Cache.SetNoStore();
if ( Request.QueryString["id"] == null )
Response.Redirect("errorpages/errorMsg.aspx?errormsg=您要查看的页面不存在!");
if ( Session["uid"] == null )
Response.Redirect("errorpages/errorMsg.aspx?errormsg=您尚未登陆!");
if ( Convert.ToInt32(Session["uid"]) != int.Parse(Request.QueryString["id"]) )
Response.Redirect("errorpages/errorMsg.aspx?errormsg=您不具有编辑他人日志的权限!");
11. 动态获取用户的主题样式
protected void Page_PreInit(object sender, EventArgs e)
{
Page.Theme = new BLL.Config().GetTheme( int.Parse(Request.QueryString["id"]) );
}
12. 在 删除 之前弹出确认对话框
this.delBlog.Attributes.Add("onclick", "return confirm('确定执行操作吗?')");
this.cancel.Attributes.Add("onclick", "return confirm('此操作将不可恢复,确定不保存日志就离开吗?')");
Response.Write("<script>window.location.href='default.aspx?id=" + int.Parse(Request.QueryString["id"]) + "';</script>");
13. 编辑器精简
function showToolbar(){document.write (
"<table border=0 cellpadding=0 cellspacing=0 width='100%' class='Toolbar' id='eWebEditor_Toolbar'><tr><td><div class=yToolbar><DIV CLASS=TBHandle></DIV><DIV CLASS=Btn TITLE='"+lang["Emot"]+"' onclick=\"showDialog('emot.htm', true)\"><IMG CLASS=Ico SRC='buttonimage/blue/emot.gif'></DIV></td></tr></table>"
);}
14. this.Session["valicode"]
this.Session["uid"]
15. ClientScript.RegisterStartupScript(this.GetType(), "info", "<script>alert('未改动任何项..!')</script>", false);
if (this.txtValiCodeNo.Text.Trim() == this.Session["valicode"].ToString())
{
}
else
{
// 验证码不正确
//HttpContext.Current.Response.Write("<script>alert('验证码输入错误!')</script>");
}
16. // 在操作完成后弹出提示信息,并跳转页面,此时跳转不是回发 !Page.IsPostBack,是首次加载
Response.Write(
"<script>alert('删除成功!');
window.location.href='default.aspx?id=" + int.Parse(Request.QueryString["id"]) + "';
</script>");
17. Repeater控件中自定义<asp:LinkButton CommandName="delBtn" CommandArguments='<%# 绑定ID %>' ></asp:linkbutton>的事件
在Repeater的ItemCommand事件中,定义
if ( e.CommandName = "delBtn" )
{
int id = Convert.ToInt32( e.CommandArguments );
}
18. 解决用户控件多次读数据库,不能数据复用的问题:
将所有用户控件写成自定义控件,在Default.aspx.cx中统一赋值。