2017/01/23

[C#][Web]統整式錯誤訊息

Using System.Web.UI
StringBuilder sbError = new StringBuilder();//紀錄錯誤訊息

sbError.Clear();//
重置錯誤訊息

//
檢查下拉值
if (string.IsNullOrEmpty(DropDownList.SelectedItem.ToString()))
        sbError.AppendFormat("請選擇DropDownList\\r\\n");

if (!string.IsNullOrEmpty(sbError.ToString()))//
錯誤跳出訊息
{       ScriptManager.RegisterClientScriptBlock(

         Page, typeof(Page), "ClientScript", "alert('" + sbError.ToString() + "')", true);
}
else
{
        //沒錯誤執行這段
}

沒有留言: