jquery datepicker not popping up? - c#

i get these errors from IE7:
Line 22: object doesnt support this property or method line 142:
invalid argument
i am trying to do a datepicker on a textbox:
<script>
jQuery(function($) {
$("#<%= report_dateTextBox.ClientID %>").mask("99/99/9999");
$("#<%= occurrence_dateTextBox.ClientID %>").datepicker();
});
here's the textbox:
<asp:TextBox ID="occurrence_dateTextBox" runat="server" size="50"/>
here's the complete code:
http://pastebin.com/Z08r6vMp
the .mask worked fine before i added the datepicker, but neither work now.
what am i doing wrong?
as TT. suggested i changed it to this:
jQuery(function($) {
//$("#occurrence_dateTextBox").mask("99/99/9999");
//$("#<%= report_dateTextBox.ClientID %>").mask("99/99/9999");
//$("#<%= occurrence_dateTextBox.ClientID %>").datepicker();
$(".datepicker").datepicker();
});
and
<asp:TextBox ID="occurrence_dateTextBox" runat="server" size="50" class="datepicker"/>
and still does not work

occurence_dateTextBox is the server ID of the control, you need the client side ID. You should also need to do the same for report_dateTextBox. I'm not sure how that was working before.
Try
$("#<%= report_dateTextBox.ClientID %>").mask("99/99/9999");
$("#<%= occurrence_dateTextBox.ClientID %>").datepicker();
Update
Here is a simplified version of your page. Any code that is not necesary has been removed.
Notice that your old version includes multiple versions of jQuery, one from Googles CDN and another locally. Now it pulls jQuery and the UI from the CDN.
You can copy and paste this into a new .aspx page and it will work.
On your own version, I suggest using Firefox and Firebug and just looking at the console to get the exact error message, because it is coming from something else other than the following code. You might not be pulling jQuery UI properly, or one of your other javascript calls is broken and it is causing problems with the datepicker.
<%# Page Language="C#" AutoEventWireup="true" CodeBehind="WebForm1.aspx.cs" %>
<!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 id="Head1" runat="server">
<title></title>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.6.4/jquery.min.js" type="text/javascript"></script>
<script src="https://ajax.googleapis.com/ajax/libs/jqueryui/1.8.16/jquery-ui.js" type="text/javascript"></script>
<script>
jQuery(function($) {
//$("#occurrence_dateTextBox").mask("99/99/9999");
//$("#<%= report_dateTextBox.ClientID %>").mask("99/99/9999");
$("#<%= occurrence_dateTextBox.ClientID %>").datepicker();
//$(".datepicker").datepicker();
});
</script>
</head>
<body><div id="container">
<form id="form1" runat="server" class="niceform">
<fieldset>
<legend>Section A</legend>
<dl>
<dt><label for="occurrence_dateTextBox" class="datepicker">Occurrence Date:</label></dt>
<dd><asp:TextBox ID="occurrence_dateTextBox" runat="server" size="50"/></dd>
</dl>
<dl>
<dt><label for="report_dateTextBox">Report Date:</label></dt>
<dd><asp:TextBox ID="report_dateTextBox" runat="server" size="50"/></dd>
</dl>
</fieldset>
<asp:Button ID="Button1" runat="server" Text="Button" />
</form>
</div></body>
</html>

Related

ASP.NET undefined from hiddenfield value

I'm trying to get the value from a hiddenfield but I'm getting an undefined alert. What am I doing wrong?
// Masterpage
...
<body>
<div class="container">
<asp:ContentPlaceHolder ID="MasterContent" runat="server"></asp:ContentPlaceHolder>
</div>
<script>
$(document).ready(function () {
alert($('#hiddenPersonId').val());
});
</script>
</body>
// Default.aspx
<asp:Content ID="Content" ContentPlaceHolderID="MasterContent" runat="Server">
<asp:HiddenField ID="hiddenPersonId" runat="server" Value="1" />
</asp:Content>
I tried other solutions but these are also not working:
alert($("#<%= hiddenPersonId.ClientID %>").val());
You could try setting ClientIDMode to static if you're .net 4+. You'll want to check that it is defined first. If you want/need the js to be on master page.
<script type="text/javascript">
$().ready(function () {
alert($('#hdnPersonId').val());
});
</script>
<asp:HiddenField ID="hdnPersonId" Value="1" runat="server" ClientIDMode="Static" />
It will not work from master page. You need to call it from Default.aspx or try
$('[id*="hiddenPersonId"]')
on master page but other pages that uses this master page should not have any control that contains hiddenPersonId in its id

jquery not working while using <form> tag

Jquery is not wrking when I am using form tag in asp.net controls.so whats the solution .I am trying multiple techniques but it does not work.
<%# Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<script type="text/javascript">
$(document).ready(function () {
$("#bt1").click(function () {
$("#p1").hide(2000);
});
});
</script>
</head>
<body>
<form id="form1" runat="server">
<div>
<p runat="server" id="p1">this is asp.net</p>
<asp:Button ID="bt1" Text="click" runat="server"/>
</div>
</form>
</body>
</html>
As you are using ASP.NET and bt1 is a button server control you need to use Control.ClientID.
<%= bt1.ClientID %> will Gets the control ID for HTML markup that is generated by ASP.NET.
Use
$("#<%= bt1.ClientID %>").click(function () {
$("#<%= p1.ClientID %>").hide(2000);
});
OR
You can use ClientIDMode.Static mode then you can continue with your existing code. However I will not recommend it.

ReferenceError: $ is not defined on jquery.are-you-sure.js [duplicate]

This question already has answers here:
JQuery - $ is not defined
(36 answers)
Closed 8 years ago.
I am a beginner in jquery
I have test.aspx page :
<%# Page Language="C#" AutoEventWireup="true" CodeFile="test.aspx.cs" Inherits="test" %>
<script type="text/javascript" src="jquery-1.8.2.min"></script>
<script type="text/javascript" src="jquery.are-you-sure.js"></script>
<script>
$(function () {
$('form').areYouSure();
$('form').areYouSure({ 'message': 'Your profile details are not saved!' });
});
</script>
<html xmlns="http://www.w3.org/1999/xhtml">
<!DOCTYPE html>
<head runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
<asp:Button ID="Button1" runat="server" Text="Button" OnClick="Button1_Click"/>
</div>
</form>
</body>
</html>
I get error:
ReferenceError: $ is not defined (Line #5)
I am tired to find the solution.
The error suggesting that you don't have jquery-1.8.2.min file at the same label where your page is.
Like suppose you have file test.aspx on root folder then your script file should on root.
And if you script file is inside a folder then you need to specify the folder name
<script type="text/javascript" src="yourFolder/jquery-1.8.2.min"></script>
I update the code, I was missing folder name.
jquery.are-you-sure.js plugin run correctly now
<%# Page Language="C#" AutoEventWireup="true" CodeFile="test.aspx.cs" Inherits="test" %>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title>Test</title>
<script type="text/javascript" src="Scripts/jquery-1.8.2.min.js"></script>
<script type="text/javascript" src="JS/jquery.are-you-sure.js"></script>
<script type="text/javascript" >
$(function () {
$('form').areYouSure();
$('form').areYouSure({ 'message': 'Your profile details are not saved!' });
});
</script>
</head>
<body>
<form id="form1" runat="server">
<asp:TextBox ID="TextBox1" runat="server"/>
<asp:Button ID="Button1" runat="server" Text="Button" OnClick="Button1_Click"/>
</form>
</body>
</html>

How to make JQuery masked-input plugin working after AsyncPostback in asp.net Ajax Update pannel?

I have a simple .aspx page and a textbox which I want to maske It using jquery.maskedinput-1.3.js and my page .aspx code is as follows , the issue is on first page load I the textbox is masked , but after an asyncPostback the masked input plugin is not working ! how can I make the masked input plugin working ? thx in advance .
<%# Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %>
<!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.js" type="text/javascript"></script>
<script src="Scripts/jquery.maskedinput-1.3.js" type="text/javascript"></script>
<script type='text/javascript'>
jQuery(function ($) {
$("#txtMembershipCode").mask("999-9999-999-9999");
});
</script>
</head>
<body>
<form id="form1" runat="server">
<asp:ScriptManager ID="ScriptManager1" runat="server">
</asp:ScriptManager>
<div style="float: right" id="exDiv">
<asp:UpdatePanel ID="UpdatePanel1" runat="server">
<ContentTemplate>
<div style="float: right; width: 120px; font-family: Tahoma">
membership Code :</div>
<div style="float: left">
<asp:TextBox ID="txtMembershipCode" runat="server" CssClass="input" ClientIDMode="Static"
dir="ltr"></asp:TextBox>
</div>
<div style="font-family: Tahoma; float: left">
<asp:Button ID="btn" runat="server" Text="save" OnClick="btn_Click" CssClass="mybtn" /></div>
<div style="font-family: Tahoma; float: right">
<asp:UpdateProgress ID="UpdateProgress1" runat="server" AssociatedUpdatePanelID="UpdatePanel1">
<ProgressTemplate>
<img src="Images/484.gif" />
</ProgressTemplate>
</asp:UpdateProgress>
</div>
</ContentTemplate>
</asp:UpdatePanel>
</div>
</form>
</body>
</html>
I have tried many different ways on the web but none of them are working !
Here is one way of solving this -
<%# Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %>
<!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.js" type="text/javascript"></script>
<script src="Scripts/jquery.maskedinput-1.3.js" type="text/javascript"></script>
<script type='text/javascript'>
window.onload = function () {
Sys.WebForms.PageRequestManager.getInstance().add_endRequest(endRequestHandler);
}
function endRequestHandler(sender, args) {
init();
}
function init() {
$("#<%=txtMembershipCode.ClientID %>").mask("999-9999-999-9999");
}
$(function() { // DOM ready
init();
});
</script>
</head>
<body>
<form id="form1" runat="server">
<asp:ScriptManager ID="ScriptManager1" runat="server">
</asp:ScriptManager>
<div style="float: right" id="exDiv">
<asp:UpdatePanel ID="UpdatePanel1" runat="server">
<ContentTemplate>
<div style="float: right; width: 120px; font-family: Tahoma">
membership Code :</div>
<div style="float: left">
<asp:TextBox ID="txtMembershipCode" runat="server" CssClass="input" dir="ltr"></asp:TextBox>
</div>
<div style="font-family: Tahoma; float: left">
<asp:Button ID="btn" runat="server" Text="save" OnClick="btn_Click" CssClass="mybtn" /></div>
<div style="font-family: Tahoma; float: right">
<asp:UpdateProgress ID="UpdateProgress1" runat="server" AssociatedUpdatePanelID="UpdatePanel1">
<ProgressTemplate>
<img src="Images/484.gif" />
</ProgressTemplate>
</asp:UpdateProgress>
</div>
</ContentTemplate>
</asp:UpdatePanel>
</div>
</form>
</body>
</html>
This approach uses the Sys.WebForms.PageRequestManager JavaScript class and is possible because you have a Script Manager on your .aspx page. Basically after every async postback the init() function will be called.
Notice the init() function is also called in DOM ready. This allows you to do everything to the DOM you need done again after content has changed during the async postback. I have used this technique before using various jQuery plugins including this one.
I used function pageLoad
<script type='text/javascript'>
function pageLoad() {
$("#<%=txtMembershipCode.ClientID %>").mask("999-9999-999-9999");
}
</script>

JQuery Check All/ Uncheck All not working on ASP.NET

$(document).ready(function() {
$('#chkRFI').click(
function() {
$("INPUT[type='checkbox']").attr('checked', $('#chkRFI').is(':checked'));
}); });
<div class="grid_3">
<div class="box">
<div class="boxheader">
<asp:CheckBox ID="chkRFI" runat="server" Text="RFI" />
</div>
<div class="boxbody">
<asp:CheckBoxList ID="chklstRFI" runat="server" CssClass="boxbodylist">
<asp:ListItem Text="RFI No" Value="RFI" />
<asp:ListItem Text="RFI Date" Value="RFI_Date" />
</asp:CheckBoxList>
</div>
</div>
</div>
How to solve? Please provide me any ideas...
Thanks
You should use $('#<%= chkRFI.ClientID %>') instead of $('#chkRFI')
I feel that solution by ysrb should work - but you may also try alternate selectors - for example:
var checkAll = $('.boxheader input');
checkAll.click(function() {
$('.boxbody input').attr('checked', checkAll.attr('checked'));
});
If you are using ASP.NET then all element IDs will be generated in very ugly form, e.g. $Form1$$MyCheckBox (in is not exactly the correct sample, but it shows the main idea). If you are using ASP.NET 4 you can disable this feature in web.config ([pages clientIDMode="static" /]). Analyze your checkbox with FireBug or simply view the page source to make sure that checkbox was generated with correct ID. Hope this helps...
<%# Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %>
<!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>Check/Uncheck All CheckBoxes Using JQuery</title>
<script src="Scripts/jquery-1.2.6.js" type="text/javascript"></script>
<script type="text/javascript">
$(document).ready(function() {
$('#chkAll').click(
function() {
$("INPUT[type='checkbox']").attr('checked', $('#chkAll').is(':checked'));
});
});
</script>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:CheckBox ID="chkAll" runat="server" Text="Check All" /><br />
<asp:CheckBoxList ID="cbList" runat="server">
</asp:CheckBoxList>
</div>
</form>
</body>
</html>
here is the complete example

Categories