Reputation: 362
I have made a very simple sample project where I want to toggle an asp .net calendar control through jquery. Could anyone please point out why it is not working. I have made no changes to master page from the sample project provided for ASP .NET web application.
<%@ Page Title="Home Page" Language="C#" MasterPageFile="~/Site.master" AutoEventWireup="true"
CodeBehind="Default.aspx.cs" Inherits="WebApplication5._Default" %>
<asp:Content ID="HeaderContent" runat="server" ContentPlaceHolderID="HeadContent">
<script type="text/javascript" src="scripts/jquery-1.4.1.min.js">
</script>
<script language="javascript" type="text/javascript">
// <![CDATA[
function Button1_onclick() {
alert( $('<%=Calendar1.ClientID%>'));
$('<%=Calendar1.ClientID%>').toggle();
}
// ]]>
</script>
</asp:Content>
<asp:Content ID="BodyContent" runat="server" ContentPlaceHolderID="MainContent">
<h2>
Welcome to ASP.NET!
</h2>
<p>
To learn more about ASP.NET visit <a href="http://www.asp.net" title="ASP.NET Website">www.asp.net</a>.
</p>
<input id="Button1" type="button" value="button" onclick="return Button1_onclick()" />
<asp:Calendar ID="Calendar1" runat="server"></asp:Calendar>
<p>
You can also find <a href="http://go.microsoft.com/fwlink/? LinkID=152368&clcid=0x409"
title="MSDN ASP.NET Docs">documentation on ASP.NET at MSDN</a>.
</p>
</asp:Content>
Upvotes: 0
Views: 6264
Reputation: 9348
To select an element by its ID on jQuery, you need to precede it with a hash (#):
function Button1_onclick() {
$('#<%=Calendar1.ClientID%>').toggle();
}
Or, if you don't want to rely on the element ID, give it a class and do it this way:
<asp:Calendar ID="Calendar1" runat="server" CssClass="myCalendar"></asp:Calendar>
function Button1_onclick() {
$('.myCalendar').toggle();
}
Upvotes: 2
Reputation: 11731
try this..
function Button1_onclick() {
alert( $('#<%= Calendar1.ClientID %>').val());
$('#<%= Calendar1.ClientID %>').toggle();
}
Upvotes: -1
Reputation: 1216
jQuery id selector starts with #
function Button1_onclick() {
alert( $('#<%=Calendar1.ClientID%>'));
$('#<%=Calendar1.ClientID%>').toggle();
}
Upvotes: 0
Reputation: 156
I think You are not getting CalendarControl's ID suing JQuery, In Jquery, if you want to access control then it can be like $('#Calendar1').toggle(); Try this one
Upvotes: 0