protected void lnkDelete_Click(object sender, EventArgs e) { try { objAttachmentcls = new AttachmentCls(); objAttachmentcls.PurposeCode = Request.QueryString["PurposeCode"]; DataTable dt = objAttachmentcls.GetPurposeCodeCount(); if (dt.Rows[0]["PurposeCodeCount"].ToString() == "0") { int res = objAttachmentcls.DeletePurpose(); if (res > 0) { ScriptManager.RegisterStartupScript(this, typeof(Page), "alert", "alert('Deleted Successfully');", true); } else { ScriptManager.RegisterStartupScript(this, typeof(Page), "alert", "alert('Not Deleted');", true); } } else { ScriptManager.RegisterStartupScript(this, typeof(Page), "alert", "alert('Purpose Code used somewhere');", true); } } catch (Exception ex) { } }