I am using jquery autocomplete and I am getting data from a generic handler that makes a call to database.
Java Script:
<script type="text/javascript">
$(document).ready(function () {
$('#managerNo').autocomplete({
source: 'ManagerHandler1.ashx'
});
});
</script>
Generic Handler: (ManagerHandler1.ashx)
public void ProcessRequest(HttpContext context)
{
string term = context.Request["term"] ?? "";
List<string> listManagerNames = new List<string>();
string myConnection = ConfigurationManager.ConnectionStrings["ArtistManagementSystem"].ConnectionString;
using(SqlConnection conn = new SqlConnection(myConnection))
{
SqlCommand cmd = new SqlCommand("spGetManagerNames",conn);
cmd.CommandType = CommandType.StoredProcedure;
cmd.Parameters.Add(new SqlParameter()
{
ParameterName = "@term",
Value = term
});
conn.Open();
SqlDataReader dr = cmd.ExecuteReader();
while (dr.Read())
{
listManagerNames.Add(dr["Cell"].ToString());
}
}
JavaScriptSerializer js = new JavaScriptSerializer();
context.Response.Write(js.Serialize(listManagerNames));
}
Actually I am trying to load numbers using autocomplete and that is working just fine. What I want to do is, Load numbers where ID = someid
.
I am getting UserID from Session on Page_Load() function.
Page_Load()
if (Session["UserID"] != null)
{
USERid = Session["UserID"].ToString();
}
I have changed the stored procedure for that and its also working fine.
StoredProcedure:
CREATE proc spGetManagerNames
@term varchar(50) = NULL,
@UsrID bigint
as
Begin
Select Cell
from Manager
where Cell like @term + '%' and [User ID]=@UsrID
End
Now since I am getting the User ID
from Session, so I want to pass that to the handler, how can I do that? Kindly help me out.