Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 5938331
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T15:40:14+00:00 2026-05-22T15:40:14+00:00

I have HTTP Handler FaqsJson.ashx which is creating a JSON utilizing the StringBuilder. In

  • 0

I have HTTP Handler FaqsJson.ashx which is creating a JSON utilizing the StringBuilder.
In this Handler Object I am calling a StoredProceedure and Im passing a single Variable FactTypeID. For now this FactTypeID is hard-coded.

From within this Handler Object I need help to be able to iterate through some other Object or Server Variable
in order to determine the Source Page which called the Object.
Also, I need to be able to call this HttpHandler from the JQuery Functions of several .aspx Pages:
Im not clear how to check from which JQuery Source Page this Handler Object was called.
I would appreciate any help as Im completely unfamiliar with HttpHandler Object.

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Text;
using System.Data.SqlClient;
using System.Configuration;

namespace DaVincisApp1
{
/// <summary>
/// Summary description for FaqsJson
/// </summary>
public class FaqsJson : IHttpHandler
{
    public void ProcessRequest(HttpContext context)
    {
        Int32 FactTypeID = 6;
        string query = "dav_getFactsByFactType " + FactTypeID;

        string connectionString = ConfigurationManager.ConnectionStrings["connectionString"].ConnectionString;
        SqlConnection myConnection = new SqlConnection(connectionString);
        SqlCommand myCommand = new SqlCommand(query, myConnection);
        try
        {
            myConnection.Open();
            SqlDataReader reader = myCommand.ExecuteReader();
            StringBuilder strFaqs = new StringBuilder();
            int start = 0;
            strFaqs.Append("[");
            while (reader.Read())
            {
                if (start == 0)
                    strFaqs.Append("{");
                else
                    strFaqs.Append(",{");

                strFaqs.Append(string.Format("\"Question\":\"{0}\",", reader[0].ToString()));
                strFaqs.Append(string.Format("\"Answer\":\"{0}\"", reader[1].ToString()));
                strFaqs.Append("}");
                start++;
            }
            strFaqs.Append("]");

            context.Response.ContentType = "application/json";
            context.Response.ContentEncoding = Encoding.UTF8;
            context.Response.Write(strFaqs.ToString());
            context.Response.End();

            reader.Close();
            myCommand.Dispose();
            myConnection.Close();
        }
        catch (Exception ex)
        {
            string exception = ex.Message;
            // Logg the exception here
        }
        finally
        {
            myConnection.Close();
            myCommand.Dispose();
        }
    }
    public bool IsReusable
    {
        get
        {
            return false;
        }
    }
}
}

Here is one of my Source Pages PaintFaqs.aspx which should pass a Parameter = 1 to the Handler
Another Source Page Glossary.aspx should pass a Parameter = 6.
I would then check that Parameter within the Handler Object to set FactTypeID

<%@ Page Title="" Language="C#" MasterPageFile="~/Site1.Master" AutoEventWireup="true"
CodeBehind="PaintFaqs.aspx.cs" Inherits="DaVincisApp1.PaintFaqs" %>

<asp:Content ID="Content1" ContentPlaceHolderID="HeadContent" runat="server">
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="MainContent" runat="server">
<script type="text/javascript">
    function ToggleFAQ(title) {
        //$("#" + title).toggle("slow");

        Aobj = document.getElementById(title);
        DIVobj = document.getElementById(title + "-link-div");
        LINKobj = document.getElementById(title + "-link-a");

        current_state = Aobj.style.display;

        if (current_state != "inline") {
            Aobj.style.display = "inline";
            Aobj.style.visibility = "visible";
            DIVobj.className = "question-clicked";
            LINKobj.className = "questionLink-clicked";
        }
        else {
            Aobj.style.display = "none";
            Aobj.style.visibility = "hidden";
            DIVobj.className = "faqquestion";
            LINKobj.className = "questionLink";
        }
    }

    $(document).ready(function () {
        $.getJSON('FaqsJson.ashx', function (datas) {
            var str = "";
            var index = 1;
            $.each(datas, function () {
                str += "<div id=\"A" + index + "-link-div\" class=\"faqquestion\">" +
                            "<a id=\"A" + index + "-link-a\" href=\"javascript://\" class=\"questionLink\" onclick=\"ToggleFAQ('A" + index + "');\">" +
                            this['Question'] +
                            "</a>" +
                       "</div>";
                str += "<div id=\"A" + index + "\" style=\"display: none;\"> " +
                            "<div class=\"faqanswer\">" +
                                "<div class=\"answerbox\">" +
                                    this['Answer'] +
                                "</div>" +
                            "</div>" +
                        "</div>";
                index++;
            });
            $("#mid-featureleft-client .controlbox").html(str);
        });
    });
</script>
<div id="top-feature-client">
    <div class="contentheader">
        <img alt="image1" src="images/Facts/FaqHeader2.png" style="height: 245px; width: 848px" />
    </div>
    <div style="clear: both;">
    </div>
</div>
<div id="mid-feature-client">
    <div id="mid-featureleft-client">
        <div class="contentheader">
            <h1>
                General Painting Facts</h1>
            <img height="16px" width="552px" src="Images/Columns/hr_red1.png" alt="" />
        </div>
        <div class="controlbox">
            <br />
        </div>
        <div style="clear: both;">
        </div>
    </div>
    <div style="clear: both;">
    </div>
</div>

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-22T15:40:14+00:00Added an answer on May 22, 2026 at 3:40 pm

    Pass your page specific FactTypeId using query string. For example,

    $.getJSON('FaqsJson.ashx?factType=1', function(...
    

    And at the handler side,

    public void ProcessRequest(HttpContext context)
    {
       int FactTypeID;
       var factType = context.Request["factType"];
       if (!string.IsNullOrEmpty(factType) && int.TryParse(factType, out FactTypeID))
       {
          // we got the fact type id
       }
       else
       {
          // error, no fact type id - return error JSON response
          // TODO
       }
    
       ...
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a Generic HTTP Handler (*.ashx) in my ASP.Net application which performs some
So... I have an http handler which serves documents. The response contentType is correctly
I have a custom Http Handler which manipulates HTTP POST and GET. I got
I Have a generic handler that's serving member logo images: http://site.com/logo.ashx?memberid=123 Now, I want
I have an HTTP server which is in our internal network and accessible only
Take a very simple case as an example, say I have this URL: http://www.example.com/65167.html
I have the following code: http://www.nomorepasting.com/getpaste.php?pasteid=22615 Which is called by the javascript mentioned in
I have an HTTP Handler that is the entry point for 90% of our
I have an HTTP Handler that is binding an XmlTextWriter instance to Response.Output like
i have written a http handler for uploading multiple files from flex application. In

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.