[RESOLVED]change the color of list on clicking anchor tag in asp.net using jquery

i am trying to change color of the list on clicking anchor tag using jquery. On clicking the anchor tag i have called a C# function code behind.. if i give return false code in jquery like the below code the color has changed. but code behind function is
not working. once i comment return false from jquery the code behind code is working but the color has not changed.

	Jquery code :

	 $(document).ready(function () {

		 $("a").click(function () {
		
			$("li.active1").removeClass("active1");

                        $(this).parent('li').addClass('active1');

			return false;
		});

	 });
	html code :

	<ul class="ullist" id="navlist">

        <li id="list1"><a id="a1" runat="server" onserverclick="lnkactive_click" style="width: 10px; position: relative">Active</a></li>

	 <li id="list2"><a id="a2" runat="server" onserverclick="lnkabeyance_click">Abeyance</a></li>
	
	</ul>

make it return true;

I think the problem is, you are trying to call both onserverclick and click .

You can see more here:

http://stackoverflow.com/questions/4830095/asp-net-button-onserverclick-only-works-when-onclick-isnt-defined

Hi januskarthik,

Thanks for your post.

As for your problem, ASP.Net AJAX ScriptManager allows us to call Server Side ASP.net methods from client side without any PostBack using PageMethods as below.

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
    <script src="../../Scripts/jquery-1.8.2.js"></script>
    <script>
        $(document).ready(function () {

            $("a").click(function () {
                $("li.active1").removeClass("active1");

                $(this).parent('li').addClass('active1');

                var id = $(this).attr("id");

                if (id == "a1") {
                    var str = PageMethods.active(OnSuccess);
                }

                if (id == "a2") {
                    var str = "World!";
                    PageMethods.abeyance(str, OnSuccess);
                }
                return false;
            });

        })

        function OnSuccess(response, userContext, methodName) {

            alert(response);

        }
    </script>
</head>
<body>
    <form id="form1" runat="server">
        <asp:ScriptManager ID="ScriptManager1" runat="server" EnablePageMethods="true"></asp:ScriptManager>

        <div>
            <ul class="ullist" id="navlist">

                <li id="list1"><a id="a1" runat="server" style="width: 10px; position: relative">Active</a></li>

                <li id="list2"><a id="a2" runat="server">Abeyance</a></li>

            </ul>
        </div>
    </form>
</body>
</html> 
[WebMethod]
public static string active()
{
    string str = "Hello World";
    return str;
}

[WebMethod]
public static string abeyance(string name)
{
    string str = "Hello "+name;
    return str;
} 

Besides, you could also refer to this article to learn about “Calling server side function from JavaScript in ASP.Net”.

If you have any question about my reply, please let me know.

Best Regards,

Fei Han

Leave a Reply