Click here to Skip to main content
13,147,182 members (27,458 online)

Asp Button Doesnt make jquery ajax call

Ehtesam Ahmed asked:

Open original thread
i just want to simply make a webmethod call from a asp button. When i use a html button it works perfectly but the asp button does not work.
my Default.aspx page is
<%@ Page Title="Home Page" Language="C#" AutoEventWireup="true"
    CodeBehind="Default.aspx.cs" Inherits="WebApplication1._Default" %>
      <script src="Scripts/jquery-1.4.1.min.js" type="text/javascript"></script>
      <script src="Scripts/myjscript.js" type="text/javascript"></script>
      <input type="submit" value="Submit" id="btnSubmit"/><br/>
      <form id="form1" runat="server">
          <asp:Button runat="server" ID="btnasp" Text="ASP Button"/>

and Default.aspx.cs code is
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.Services;
namespace WebApplication1
    public partial class _Default : System.Web.UI.Page
        protected void Page_Load(object sender, EventArgs e)
        public static string getDate()
            return DateTime.Now.ToString();
Jscript file is
$(function () {
    $("#btnSubmit").bind("click", onClick);
    $("#btnasp").bind("click", onASPClick);
function onClick() {
    alert("I am a HTML Submit Button");

function onASPClick() {
    alert("I am a Button");

function callMethod() {
        url: 'Default.aspx/getDate',
        type: "POST",
        data: "{}",
        contentType: "application/json; charset=utf-8",
        dataType: "json",
        success: function (data) {
somebody please help.
Tags: ASP.NET, Ajax, jQuery


When answering a question please:
  1. Read the question carefully.
  2. Understand that English isn't everyone's first language so be lenient of bad spelling and grammar.
  3. If a question is poorly phrased then either ask for clarification, ignore it, or edit the question and fix the problem. Insults are not welcome.
Let's work to help developers, not make them feel stupid.
Please note that all posts will be submitted under the The Code Project Open License (CPOL).

Advertise | Privacy |
Web02 | 2.8.170915.1 | Last Updated 26 Mar 2009
Copyright © CodeProject, 1999-2017
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100