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

  • SEARCH
  • Home
  • 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 8753569
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T13:27:10+00:00 2026-06-13T13:27:10+00:00

Im using Jquery Post in my code, and Im wonder how can I call

  • 0

Im using Jquery Post in my code,
and Im wonder how can I call back from the server, to my HTML page..

this is my Jquery code :

function InsertMemo() {

$('#buttonComplain').bind('click', function () {

    var noteMemo = $('#noteId').val();
    var url = "Handlers/Handler.aspx";

    $.post(url,
         { noteMemo: noteMemo },
          function () {

              hideMemoShowCons();


          }
     );
});

}

I want in the function, to call back from my code in C# :

protected void Page_Load(object sender, EventArgs e)
        {
              rndSntnc = RandomSentnce();
        }

and then to pase it to my HTML :

 <div class="cons">
               <%=thecodeExample %>
            </div>

how do I do that ?

  • 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-06-13T13:27:12+00:00Added an answer on June 13, 2026 at 1:27 pm

    You wouldn’t necessarily want to run Page_Load again. I mean, you could (and most ajax in web form development does run through the full page life cycle), but if there’s no dependencies on any other part of the page, It’d probably just make more sense to make RandomSentnce a static WebMethod

    [WebMethod]
    public static string RandomSentnce ()
    {
         ... get your random sentence here ..
    }
    

    And do something like

    $.ajax({
      type: "POST",
      url: "PageName.aspx/RandomSentnce",
      data: "{}",
      contentType: "application/json; charset=utf-8",
      dataType: "json",
      success: function(msg) {
        // Do something interesting here.
      }
    });
    

    WebMethods do not go through the whole asp.net web forms life cycle, so they’re generally faster, too.

    Do you know which div needs to have its content replaced at the time of the invocation? If so, it would also make sense to give the div an ID so you can find it in your success method above, so you could just do:

      ...
      success: function(msg) {
          $("#myDivID").text(msg.d);
      }
      ...
    

    If it’s something where you only know by clicking on it, you’d just have to capture a reference to the element when you invoke the ajax call and use that reference in the success method (or, using jQuery promises, you don’t strictly have to pass in a success method, but I won’t go into that now).

    BTW I don’t have all this memorized, I used http://encosia.com/using-jquery-to-directly-call-aspnet-ajax-page-methods/ as a source. If there’s anything wrong with what I said, consult that source.

    Edit:

    You ask: First : on the $.ajax, on the url.. when you typed “PageName.aspx/RandomSentnce”, it means that you go directly to the function?! and second : on the success function, what the “d” means in the $(“#myDivID”).text(msg.d); ?

    Answer to #1: Not sure what you mean by “go” here, but that’s how the url is structured for web methods on aspx pages, and, from your page, only that function will be invoked.

    Answer to #2: by default (as of asp.net 3.5+), WebMethod responses get wrapped in a object “for security concerns” (see What does .d in JSON mean? and http://encosia.com/a-breaking-change-between-versions-of-aspnet-ajax/). Basically, the body of your response will look like {"d":"..."} which will get parsed into a javascript object (the first parameter to your success function), and to get to your method’s result, you just grab the d property of the aforementioned object.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

How to pass multiple checkboxes using jQuery ajax post this is the ajax function
I am using jQuery's $.post function to retrieve some data from a php file,
using jquery's .post i send do my php code an object that with var_dump
I have the following snippet of code (I'm using jQuery 1.4.2): $.post('/Ads/GetAdStatsRow/', { 'ad_id':
I am using jquery post to submit data on server and data having json
I have written a form using the jQuery .post() function to post the data
I am testing a website in Firefox 8. I am using a jQuery.post call
I am trying to call ASP.net 1.1 service in asp.net using Jquery, can't figure
I am fetching Google in a gadget using this code: <html> <head> <title>Browser</title> </head>
Using jQuery and the HTML below, can someone please suggest what's the best (ie.

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.