验证文本不能为空 不用控件
public partial class NewsEditor : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
if (Request["id"] != "0")
{
title.Text = News_BLL.TextListSingle(int.Parse(Request["id"]))[0].title;
editor.Text = News_BLL.TextListSingle(int.Parse(Request["id"]))[0].content;
}
}
}
protected void submit_Click(object sender, EventArgs e)
{
bool status;
editor.Text = News_BLL.EditorBug(editor.Text);
if (Request["id"] != "0")
{
status = News_BLL.TextListUpdate(title.Text, editor.Text, int.Parse(Request["id"]));
}
else
{
status = News_BLL.TextListInsert(1001, title.Text, editor.Text);这里 }
if (status) { Server.Transfer("News.aspx?id=" + Request["uid"]); }
}
}
------解决方案--------------------
else
{
if(string.isNullOrEmpty(title.Text))
{
return;
}
status = News_BLL.TextListInsert(1001, title.Text, editor.Text);这里 }
if (status) { Server.Transfer("News.aspx?id=" + Request["uid"]); }
}
------解决方案--------------------
if (Request["id"] != "0")
{
status = News_BLL.TextListUpdate(title.Text, editor.Text, int.Parse(Request["id"]));
}
else
{
if(title.Text.Trim().Length>0)
//正常执行
else
{
ClientScript.RegisterStartupScript(this.GetType(), "abc", "<script>alert('不能为空!')</script>");
return;
}
}