Click here to Skip to main content
15,881,812 members
Please Sign up or sign in to vote.
4.00/5 (1 vote)
See more:
Hi Guys, i was tried to fire the asp button using jquery but it does not working. My code is:

XML
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="DivMoving.aspx.cs" Inherits="DivMoving" %>

<!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>Untitled Page</title>

    <script src="js/jquery-1.8.0.min.js" type="text/javascript"></script>
    <script type="text/javascript">
    $(function()    {
    $("#btnLeft").click(function()
    {
        $("#divblock").animate(
       {"left":"-=50px"},"slow");


    });
    $("#btnRight").click(function()
    {
     $("#divblock").animate({"left":"+=50px"},"slow");

    });

    });


    </script>
    <style type="text/css">
    div
    {
        position:absolute ;
        background-color:Maroon ;
        left:100px;
        width:120px;
        height:80px;
    }


    </style>
</head>
<body>
<form id="frm" runat="server" >
<asp:Button ID ="btnLeft" runat="server" Text="<<"/>
&nbsp;
<asp:Button ID="btnRight" runat="server" Text=">>"/>
<div id="divblock"></div>



<%--<button id="btnLeft" runat="server"  >&laquo;</button>
&nbsp; &nbsp; &nbsp;

<button id="btnRight" runat="server"  >&raquo;</button>

<div id="divblock" ></div>--%>
     </form>
</body>
</html>


Here only fires HTML controls. but not server side controls.

Please help me...
Posted
Updated 4-Sep-12 21:15pm
v3

JavaScript
$("input[id$='btnLeft']").click(function() {
    $("#divblock").animate(
       {"left":"-=50px"},"slow");
 
  });



Check this out..it will work..!
 
Share this answer
 
Comments
CH Guravaiah 5-Sep-12 2:28am    
thanks for reply, But it does not working.
Try this

$("#"+"<%=btnLeft.ClientID%>").click(function() {
    $("#divblock").animate(
       {"left":"-=50px"},"slow");
 
  });


$("#"+"<%=btnRight.ClientID%>").click(function()
    {
     $("#divblock").animate({"left":"+=50px"},"slow");
 
    });
 
Share this answer
 
Comments
CH Guravaiah 5-Sep-12 2:39am    
sorry , it is also doesn't working. i was tried put the code in different ways like :$("#"+"<%=btnRight.ClientID%>").click(function() (or) $("#'<%=btnLeft.ClientID %>'").click(function() (or) $("#btnLeft").click(function() all are doesn't work and also all code pasted above.
Hi,

JavaScript understand only ClientID. JQuery is also javascript extension. You need to pass Button ClientID not the ServerId. In your case btnLeft is ServerID. I suggest you to use fix ClientID or get ClientId from javascript like,

JavaScript
$("#'<%=btnLeft.ClientID %>'");


Hope this helps you,
Thanks
-Amit Gajjar
 
Share this answer
 
XML
$(document).ready(function () {
            $('#<%= btnLeft.ClientID %>').click(function () {
                $("#divblock").animate({"left":"-=50px"},"slow");
            });
            $('#<%= btnRight.ClientID %>').click(function () {
                $("#divblock").animate({"left":"+=50px"},"slow");
            });
        });


Check this out it tested on my side....m sure it will work 100%..!
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900