ASP.NET Alert box from Class

toorieesogera

New Member
I'm using a class "Service" to connect to a DB and return a DataTable to my ASP.NET page.I'm using try/catch to catch SqlExceptions. I want to display the exception text to the user in an Alert box. How do I do this?This is my function in Service.class:\[code\]using System;using System.Collections.Generic;using System.Data;using System.Data.SqlClient;using System.Linq;using System.Text;using System.Threading.Tasks;using System.Web;namespace Classes{ public class Service { private static DataTable getDataTable(string query) { DataTable dt = null; SqlConnection con = Dao.getConnection(); if (Dao.checkConnection()) { SqlDataAdapter da = new SqlDataAdapter(query, con); dt = new DataTable(); try { da.Fill(dt); } catch (SqlException ex) { //MessageBox.Show(ex.Message); Response.Write("<script>alert('This is Alert');</script>"); //HttpContext.Current.Response.Write(); //ScriptManager.RegisterClientScriptBlock(this, this.GetType(), " ","alert('ERROR')", true); //var clientScript = Page.ClientScript; //clientScript.RegisterClientScriptBlock(null, "AlertScript", "alert('ERROR')'", true); //System.Diagnostics.Debug.WriteLine("Database error: " + ex.Message); } } return dt; }\[/code\]The compiler gives me this: The name 'Response' does not exist in the current context.I guess it's pretty basic, just haven't been able to find the answer yet.The commented stuff is what I tried so far!
 
Back
Top