using System.Configuration;
using System.Data;
using System.Data.SqlClient;
using System.Web.Script.Serialization;
using System.Web.Services;

namespace Asp.netTooltipUsingJqueryUI
{

    [WebService(Namespace = "http://tempuri.org/")]
    [WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
    [System.ComponentModel.ToolboxItem(false)]
    [System.Web.Script.Services.ScriptService]
    public class TooltipDataService : System.Web.Services.WebService
    {
        [WebMethod]
        public void GetTooltipData(string controlName)
        {
            string CS = ConfigurationManager.ConnectionStrings["DBCS"].ConnectionString;

            Tooltip toolTip = new Tooltip();

            using (SqlConnection con = new SqlConnection(CS))
            {
                con.Open();
                SqlCommand cmd = new SqlCommand("spGetTooltipData", con);
                cmd.CommandType = CommandType.StoredProcedure;

                cmd.Parameters.AddWithValue("@controlName", controlName);

                SqlDataReader dr = cmd.ExecuteReader();

                while(dr.Read())
                {
                    toolTip.controlName = dr["controlName"].ToString();
                    toolTip.tooltipData = dr["tooltipData"].ToString();
                }

                JavaScriptSerializer serializer = new JavaScriptSerializer();
                Context.Response.Write(serializer.Serialize(toolTip));
            }
        }
    }
}
