C#中,由于.net不能及时更新,就会出现以下这种情况:
User已经点开链接在看东西,Admin于此时出于某种原因把把链接的页面删除掉了,此时User如果想在链接的页面里做些什么,如提交之类操作,页面就会出现一大堆错识,这样看起来很不好,我们此时需要提醒User该信息不存在。
解决方法: 在PageLoad事件里写上try...catch,任何异常用catch告诉对方就好了
eg:
protected void Page_Load(object sender, EventArgs e)
{
//获取ID
string StrID = Server.UrlDecode(Request.QueryString["id"]);
if (!IsPostBack)
{
try
{
if (StrID != null)
{
UDS.Components.SchoolPublic act = new UDS.Components.SchoolPublic();
int intID = Int32.Parse(StrID);
string Path = "";
DataTable dt = act.GetInfoFileID(intID);
TextBoxTitle.Text = dt.Rows[0]["File_Title"].ToString();
this.FreeTextBox1.Text = dt.Rows[0]["Summary"].ToString();
TextBoxTime.Text = dt.Rows[0]["Up_Time"].ToString();
TextBoxMemo.Text = dt.Rows[0]["File_Memo"].ToString();
Path = dt.Rows[0]["File_Path"].ToString();
if (Path == "")
{
this.btnDownload.Text = "(没有附件下载)";
this.btnDownload.Enabled = false;
}
else
{
this.btnDownload.Text = "有附件(请点击下载)";
}
}
}
catch
{
Response.Write("<script language='javascript'>alert('此信息已被删除!');window.location.href='SchPubBrowser.aspx'</script>");
}
}