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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T23:46:15+00:00 2026-05-17T23:46:15+00:00

When I click on the following div: <div id=Result>Click here for the time.</div> I

  • 0

When I click on the following div:

 <div id="Result">Click here for the time.</div>

I need the following codebehind function to run:

 <WebMethod()> _
 Public Shared Function GetDate() As String
     Return DateTime.Now.ToString()
 End Function

I need this to populate the inside of the div with the string returned by the GetDate() function. I think this should use code similar to this:

<script type="text/javascript">
    $(document).ready(function () {
        // Add the page method call as an onclick handler for the div.
        $("#Result").click(function () {
            $.ajax({
                type: "POST",
                url: "test.aspx/GetDate",
                data: "{}",
                contentType: "application/json; charset=utf-8",
                dataType: "json",
                success: function (msg) {
                    // Replace the div's content with the page method's return.
                    $("#Result").text(msg.d);
                }
            });
        });
    });
</script>

I’ve pulled this example from this site: http://encosia.com/2008/05/29/using-jquery-to-directly-call-aspnet-ajax-page-methods/

However, I simply cannot get it to work. Nothing happens. This is just a regular asp.net web project. I haven’t done any sort of Ajax-enabling business other than including script tags in my markup to reference jquery.

Here’s what the firebug console tells me when I click on the div:

 POST http://admin/Default.aspx   GetDate   404 Not Found   -18ms

Edit: Note: test.aspx/GetDate must match your aspx page name and function name!

  • 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-17T23:46:15+00:00Added an answer on May 17, 2026 at 11:46 pm
    <WebMethod()> _
    Public Shared Function GetDate() As String
        Return DateTime.Now.ToString()
    End Function
    

    Gotta be “Shared” (“static” in C#)

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

Sidebar

Related Questions

I have the following code: <script> $(document).ready(function() { $('.toggle_section').click(function(e){ parent = $(e.target).closest(div) objChild =
The following XAML produces a run-time Binding error when I click on an item
I have the following function: jQuery(document).ready(function($){ $(div.findButton).click(function(){ UidID=Math.floor(Math.random()*1000); PostCode=$(#postcode).val(); $.get(result.php, {postcode: PostCode,uid:UidID}, function(response){ $(#result).html(response);
I have a question about jQuery load best practice. Imagine the following situation: $(#div).on('click',
Say I have the following code: <div onclick='location.href=http://www.example.com/'> <a href='#' onclick='alert(blah)'>click</a> </div> Is there
I am trying to accomplish the following: 1. On click, have a div with
I have the following click event $(.element).click(function() { var idNum = $(this).getID; $('#new-'+idNum).fadeIn(); });
When I click the submit button in the following form, my jQuery GET function
I have the following html code: <div id=result1 class=result> ... some html ... ...
I have the following ajax success function. How can I act on the result

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.