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.
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:
and js:
That should work.