TECHNOLOGIES
FORUMS
JOBS
BOOKS
EVENTS
INTERVIEWS
Live
MORE
LEARN
Training
CAREER
MEMBERS
VIDEOS
NEWS
BLOGS
Sign Up
Login
No unread comment.
View All Comments
No unread message.
View All Messages
No unread notification.
View All Notifications
Answers
Post
An Article
A Blog
A News
A Video
An EBook
An Interview Question
Ask Question
Forums
Monthly Leaders
Forum guidelines
Jes Sie
741
1.2k
281.3k
How to call generic handler with 2 parameters in webforms
Feb 26 2018 1:40 AM
Hello everybody, I created a general handler which will display names of students. This handler has 2 parameters namely: SchoolCode and term. The first parameter is loaded in my webform on page load. The 2nd parameter is when I type the name of the student in the textbox. Please refer to my code snippet below,
public
void
ProcessRequest(HttpContext context)
{
string
SchoolCode = context.Request[
"SchoolCode"
] ??
""
;
string
term = context.Request[
"term"
] ??
""
;
List<
string
> studentName =
new
List<
string
>();
using
(SqlConnection con = DBCS.GetConString())
{
SqlCommand cmd =
new
SqlCommand(
"spDropdownList_Student"
, con);
cmd.CommandType = CommandType.StoredProcedure;
cmd.Parameters.AddWithValue(
"@SchoolCode"
, SchoolCode);
cmd.Parameters.AddWithValue(
"@term"
, term);
con.Open();
SqlDataReader rdr = cmd.ExecuteReader();
while
(rdr.Read())
{
studentName.Add(rdr[
"StudentDetails"
].ToString());
}
}
JavaScriptSerializer js =
new
JavaScriptSerializer();
context.Response.Write(js.Serialize(studentName));
}
Below is my stored proc:
ALTER
PROCEDURE
[dbo].[spDropdownList_Student]
-- Add the parameters for the stored procedure here
@SchoolCode nvarchar(50),
@term nvarchar(50)
AS
BEGIN
-- SET NOCOUNT ON added to prevent extra result sets from
-- interfering with SELECT statements.
SET
NOCOUNT
ON
;
-- Insert statements for procedure here
SELECT
[Fname] +
' '
+ [Lname] +
' - '
+ [NickName]
as
StudentDetails
FROM
[dbo].[tblStudentMaster]
WHERE
[SchoolCode] = @SchoolCode
AND
[Fname]
LIKE
@term +
'%'
ORDER
BY
[Fname]
ASC
END
I tested my sp and it's working fine. Below also is the result:
Now, in my webforms, I made a jquery function to call the handler:
$(document).ready(function () {
$('#MasterFileContentSection_txtStudentName').autocomplete({
source: '/Handlers/StudentName.ashx'
});
});
but it didn't display the names of students. I'm new jquery.
Reply
Answers (
2
)
data not loading in gridview
How to use Etag when showing data through aspx file