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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T08:59:23+00:00 2026-05-24T08:59:23+00:00

I have only one button and I mention what to do when user click

  • 0

I have only one button and I mention what to do when user click on the button with the help of jQuery. but when I click then nothing happen just only postback happen. I don’t want a postback.

Here is my code:

<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="WebForm1.aspx.cs" Inherits="BBAWeb.WebForm1" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
        <script src="Scripts/jquery-1.6.2.min.js" type="text/javascript"/>
    <script type="text/javascript">
        $(document).ready(function () {
            $('#btn').click(showMessage);
            return false;
        });

        function showMessage() {
            $('#message').fadeIn('slow').html("Hello");
        }  
    </script>
</head>
<body>
    <form id="form1" runat="server">
    <div>
        <asp:Button ID="btn" runat="server" Text="Click Me" />
        <div id="message">welcome to kolkata</div>
    </div>
    </form>
</body>
</html>

Please see my code and tell me what is wrong in it. I would like a suggestion.

  • 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-24T08:59:23+00:00Added an answer on May 24, 2026 at 8:59 am

    Firstly, when the button finally gets displayed on the page, asp.net will change the button id to more unique so it can manage everything better.

    so your jquery $(“btn”) would not be able to find anything.

    instead, just add a class, say, “myBtn” to your button and do this:

    <asp:Button ID="btn" runat="server" Text="Click Me" CssClass="myBtn" />
    

    and js:

    <script>
    $(".myBtn").click(function(event) {
      event.preventDefault();
      showMessage();
    });
    </script>
    

    That should work.

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

Sidebar

Related Questions

I have an application with only one button. When user clicks the button, a
I have an activity class with many buttons. If i click one button then
I made shoot em up like game.But I have only one ememy which fallows
I have two sites with different SITE_IDs, but I want to have only one
I have an app that lets the users chose one and only one button
I just learned that an object can have only one ID, so I'm not
I have only one class with many instances. Every instance is observer of couple
Are there good reasons why it's a better practice to have only one return
I need to make so that my application can have only one instance running
Greetings, I would like to ask if creating Singleton to have only one active

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.