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 6783117
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T16:49:34+00:00 2026-05-26T16:49:34+00:00

The objective is to call a method which does it’s thing then returns a

  • 0

The objective is to call a method which does it’s thing then returns a JSON object.

I’m new to JSON.

I have a default.aspx and in it the following code. Now I want an ordinary method in Default.aspx.cs to run on the click event here.

$(".day").click(function (event) {
var day = $(event.currentTarget).attr('id');
if (day != "") {
    $.ajax(
    {
        type: "POST",
        async: true,
        url: 'Default.aspx?day=' + day,
        data: day,
        contentType: "application/json; charset=utf-8",
        dataType: "json",
        success: function (msg) {
            console.log("SUCCESS:" + msg);
            //  $(".stripp img").attr('src', "data:image/jpg;" + msg);
            //  $(".stripp").show();
        },
        error: function (msg) {
            console.log("error:" + msg);
        }
    });
}

});

Default.aspx.cs looks similar to this:

    protected void Page_Load(object sender, EventArgs e)
    {
        if (Request.QueryString["day"] != null)
            GetFile(Request.QueryString["day"]);
    }
    public string GetFile(string day)
    {
        string json = "";
        byte[] bytes = getByteArray();

        json = JsonConvert.SerializeObject(bytes);
        return json;
    }

Where am I going wrong here?
Should I be using this in some way or is it only applicable in Web Services?

    [WebMethod]
    [ScriptMethod(ResponseFormat = ResponseFormat.Json)]
  • 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-26T16:49:34+00:00Added an answer on May 26, 2026 at 4:49 pm

    I would suggest an HttpHandler. No page lifecycle (so it is blazing fast) and much cleaner code-separation, as well as reusability.

    Add a new item to your project of type “Generic Handler”. This will create a new .ashx file. The main method of any class that implements IHttpHandler is ProcessRequest. So to use the code from your original question:

    public void ProcessRequest (HttpContext context) {
    
        if(String.IsNullOrEmpty(context.Request["day"]))
        {
            context.Response.End(); 
        }
    
        string json = "";
        byte[] bytes = getByteArray();
    
        json = JsonConvert.SerializeObject(bytes);
        context.Response.ContentType = "text/json";
        context.Response.Write(json);
    }
    

    Change the url in your AJAX call and that should do it. The JavaScript would look like this , where GetFileHandler.ashx is the name of the IHttpHandler you just created:

    $.ajax(
        {
            type: "POST",
            async: true,
            url: 'Handlers/GetFileHandler.ashx',
            data: "Day=" + $.toJSON(day),
            contentType: "application/json; charset=utf-8",
            dataType: "json",
            success: function (msg) {
                console.log("SUCCESS:" + msg);
            },
            error: function (msg) {
                console.log("error:" + msg);
            }
        });
    

    Another small point to consider, if you need access to the Session object from within the Handler code itself, make sure to inherit from the IRequiresSessionState interface:

    public class GetFileHandler : IHttpHandler, IRequiresSessionState
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have an objective-C++ class which contain some honest C++ object pointers. When the
I'm new to Objective-C and iPhone SDK development. I want to call a method
I have a new MacRuby application. I'm trying to call a MacRuby method from
I have some code in objective-C which uses the 'mutableCopy' method to make a
I have created a library which can download JSON data which is then placed
Can I intercept a method call in Objective-C? How? Edit: Mark Powell 's answer
You can use a standard dot notation or a method call in Objective-C to
What is the normal behavior in Objective-C if you call a method on an
This is an objective-c question. I would like to call a method in an
I have a Java program (call it Jack) and an Objective-C program (call it

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.