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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T03:16:57+00:00 2026-06-18T03:16:57+00:00

I’m new to integrating JavaScript into a web site, but I’m going to need

  • 0

I’m new to integrating JavaScript into a web site, but I’m going to need it often in my web site.

Here is an example:
Assuming I have the function:

showAlert()

Say I have:

<div id="some_div">

</div>

Could someone provide me some kind of example that would do this:
If I have a button and the user clicks it, this should raise an event in the backend and call some method in my C# file. Then my C# file should be able to call some other javascript method of the front end which would call showAlert() and display the alert in the div.

This is what I can’t seem to find any information on.

The basic idea of passing information to and from the server. Any help with this would be really appreciated.

Thanks

  • 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-18T03:16:58+00:00Added an answer on June 18, 2026 at 3:16 am

    Your best bet is to use a framework like jquery, then bind to the button, call the service, and handle the response. The below is a quick example of this.

    $(document).ready(function()
        $('#Button1').bind('click', function () { 
            // This grabs the page you are in so that you can call it correctly
            var pagePath = window.location.pathname;  
            var testId = $("#some_div").val();
            var url = pagePath + "/TestService";          
            $.post(url, { id: testId },
                function (data) {
                    showAlert(data);
                }
            });
        };
    });
    

    First, you need to make sure the document is ready at some point. Bind allows the the button to be bound when the document loads. Then, by clicking it, you execute the anonymous function that grabs the testId, calls your service, and handles the data response in a success callback.

    Hope that gets you started in the right direction!

    EDIT: Added backend webforms “service” exposure

    public partial class _Default : System.Web.UI.Page 
    {
        protected void Page_Load(object sender, EventArgs e) 
        {
    
        }
    
        [WebMethod]
        public static string TestService(string id) 
        {
            var string = DBCollection.FirstOrDefault(x => x.id == id); // Or whatever you want to return the data
            return "You called me on " + DateTime.Now.ToString() + "with " + string;
        }
    }
    

    This would allow you to call the “WebMethod exposed on your page. For more help with this, please see the following link.

    http://www.tugberkugurlu.com/archive/asp-net-web-forms—calling-web-service-page-methods-using-jquery

    EDIT: Additional Considerations when performing this type of approach in webforms.
    Calling a webmethod with jquery in asp.net webforms

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

Sidebar

Related Questions

I have a French site that I want to parse, but am running into
I have a .ini file as follows: [playlist] numberofentries=2 File1=http://87.230.82.17:80 Title1=(#1 - 365/1400) Example
link Im having trouble converting the html entites into html characters, (&# 8217;) i
this is what i have right now Drawing an RSS feed into the php,
I have a small JavaScript validation script that validates inputs based on Regex. I
This could be a duplicate question, but I have no idea what search terms
I have thousands of HTML files to process using Groovy/Java and I need to
I need to clean up various Word 'smart' characters in user input, including but
Seemingly simple, but I cannot find anything relevant on the web. What is the
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function

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.