My jQuery is not working - asp.net

<%# Page Language="VB" AutoEventWireup="false" CodeFile="Default.aspx.vb" 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>Untitled Page</title>
<script language="javascript" type="text/javascript">
$(document).ready(function()
{
$(".button1").click(function ()
{
$("p").hide("slow");
});
$(".button2").click(function ()
{
$("p").show("slow");
});
});
</script>
</head>
<body>
<form id="form1" runat="server">
<input id="Button1" type="button" value="button" class="button1"/>
<input id="Button2" type="button" value="button" class="button2"/><h2>Welcome to F5 Technologies </h2>
<p>&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp F5 Technologies is a rapidly developing company, acquiring its position on the business market,
Our company helps make products
delivery more effective, efficient, and meaningful to our customers, and allow them to take greater
responsibility for their own new products.Software is developed by the most experienced development staffs. </p>
</form>
</body>
</html>

you need to include the jQuery library.
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.3/jquery.min.js"></script>

You didn't include the jQuery library itself:
<script src="jquery.min.js" type="text/javascript">
</script>
You can also include it from a CDN:
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.0/jquery.min.js"
type="text/javascript"></script>

Despite my comment on the question, it looks like the main culprit is that you aren't actually referencing the jQuery JS file. Try something like:
<script type="text/javascript" src="Scripts/jquery-1.3.2.js"></script>

Related

Datepicker on a textbox in asp.net is not working

This is my JS for the datepicker.
<script type="text/javascript">
$(document).ready(function () {
$(function () {
$("#txtage").datepicker();
});
});
</script>
This is my asp server side control.
<asp:TextBox ID="txtage" runat="server" ReadOnly="true"></asp:TextBox>
I want when user reach on this textbox then one calender should open from which they can select age and that date should display into this textbox.
Please tell me how can i do this?
You have several problems. Your ID doesn't match. You're using txtage in one place and txtcity in another. Is that a copy paste error?
If you're using nested templated controls (or a master page), your ID's on the client side are likely different than on the server side. You can change how the ID's on the client side are generated like this:
<link rel="stylesheet" href="//code.jquery.com/ui/1.11.4/themes/smoothness/jquery-ui.css" />
<script src="//code.jquery.com/jquery-1.10.2.js"></script>
<script src="//code.jquery.com/ui/1.11.4/jquery-ui.js"></script>
<link rel="stylesheet" href="/resources/demos/style.css" />
<script type="text/javascript">
$(document).ready(function () {
$(function () {
$("#txtage").datepicker();
});
});
</script>
<td><asp:TextBox ID="txtage" runat="server" ClientIdMode="static" /></td>
You also haven't shown your code for making sure jQuery and jQuery UI are loaded on the page.
I just checked and this one works perfectly :
Default.aspx
<%# Page Language="C#" AutoEventWireup="true" CodeBehind="Default.aspx.cs" Inherits="testDatePicker.Default" %>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
<title></title>
<link rel="stylesheet" href="//code.jquery.com/ui/1.11.4/themes/smoothness/jquery-ui.css" />
<script src="//code.jquery.com/jquery-1.10.2.js"></script>
<script src="//code.jquery.com/ui/1.11.4/jquery-ui.js"></script>
<link rel="stylesheet" href="/resources/demos/style.css" />
<script src="script.js"></script>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:TextBox runat="server" ID="myTextBox"></asp:TextBox>
</div>
</form>
</body>
</html>
script.js
$(function() {
$("#myTextBox").datepicker();
});
I may advice you to remove the ReadOnly proprety since the datepicker will try to modify the textBox but not so sure.
Just add .ClientID with the textbox id as follows.
JS
<link rel="stylesheet" href="http://code.jquery.com/ui/1.11.0/themes/smoothness/jquery-ui.css">
<script src="http://code.jquery.com/jquery-1.10.2.js"></script>
<script src="http://code.jquery.com/ui/1.11.0/jquery-ui.js"></script>
<script type="text/javascript">
$(document).ready(function () {
$(function () {
$('#<%=txtage.ClientID%>').datepicker();
});
});
Asp.Net takes a property that is TextMode That loads a calendar, which has to be equal "Date" - TextMode="Date".
Example:
<asp:TextBox ID="txtage" TextMode="Date" runat="server" ReadOnly="true"></asp:TextBox>

My required field validation of jQuery is not working

I have aspx page where only one text box will be a required field. I am using JQuery to validate it.
My problem is the client side validation is not working.
The head section of my page is
<script src="../JavaScript/jquery-1.6.1.min.js" type="text/javascript"></script>
<script src="../JavaScript/jquery.validate.js" type="text/javascript"></script>
<script src="../JavaScript/CandidateValidation.js" type="text/javascript"></script>
<script type="text/javascript">
$(document).ready(function(){
checkRequiredInputs();
});
</script>
The CandidateValidation.js file contains
function checkRequiredInputs(){
$(".requiredField").validate({
rules:{
txtFName:{required: true}
},
messages:{
txtFName:"Name Required"
}
});
}
I have a CSS CLass lin my CSS File like
.requiredField
{
}
The Text box where for this input is
I need a suggestion or solution from you programmers,the most helpful I have ever found, from this helpful sites, waiting for your reply. Thanx in advance
For the code to work you will need to call validate() on the form containing your textbox.
For example:
[WebForm1.aspx]
<%# Page Language="C#" AutoEventWireup="true" CodeBehind="WebForm1.aspx.cs" Inherits="Validation.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">
<link href="../Css/StyleSheet1.css" type="text/css" rel="Stylesheet" />
<script src="../JavaScript/jquery-1.6.1.min.js" type="text/javascript"></script>
<script src="../JavaScript/jquery.validate.js" type="text/javascript"></script>
<script src="../JavaScript/CandidateValidation.js" type="text/javascript"></script>
<script type="text/javascript">
$(document).ready(function(){
checkRequiredInputs();
});
</script>
<title></title>
</head>
<body>
<form id="form1" runat="server" clientidmode="Static" >
<asp:TextBox runat="server" ID="txtFName" />
</form>
</body>
</html>
[CandidateValidation.js]
function checkRequiredInputs(){
$("#form1").validate({
rules:{
txtFName:{required: true}
},
messages:{
txtFName:"Name Required"
}
});
}
Setting clientidmode="Static" on form1 will make it have same ID on client side so it can be referenced easily from jQuery.
If you press enter in txtFName TextBox to submit validation will be performed on the form:

Changing content on ASP.NET using AJAX

I have this asp.net code in my page :
<div id="prx">ABC</div>
And I want to change the value "ABC" to something when for example the user type a value in TextBox.
How can I do that using Ajax ?
Thanks
You don't need AJAX to do this. You can simply use Javascript to update the content of the DIV tag with the contents of the INPUT widget. See How to set the value of a form element using Javascript.
Now if you'd like to update the TextBox with something from the server without reloading the page, then that's AJAX. I'd use jQuery.ajax() function over UpdatePanels though. Here's a jQuery AJAX Tutorial.
May be using javascript?)
<%# Page Language="C#" AutoEventWireup="true" CodeBehind="WebForm2.aspx.cs" Inherits="WebApplication11.WebForm2" %>
<!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 type="text/javascript">
function setDivContent() {
var textInput = document.getElementById('text1');
var divPrx = document.getElementById('prx');
divPrx.innerHTML = textInput.value;
}
</script>
</head>
<body>
<form id="form1" runat="server">
<div>
<div id="prx">ABC</div>
<br />
<input type="text" id="text1" />
<button onclick="javascript:setDivContent(); return false;">Set</button>
</div>
</form>
</body>
</html>
Check out the ASP.NET AJAX UpdatePanel control. It lets you change text on a page and "AJAX-ifies" anything inside it, instead of doing a full postback. Here is a good tutorial on it.
I know this is old question.. but it might help someone
JQUERY for this would be :
<html xmlns="http://www.w3.org/1999/xhtml">
<head id="Head1" runat="server">
<title></title>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script>
<script>
$(document).ready(function(){
$("#btn1").click(function(e){
e.preventDefault();
$("#prx").text($("#text1").val());
});
});
</script>
</head>
<body>
<form id="form1" runat="server">
<div>
<div id="prx">ABC</div>
<br />
<input type="text" id="text1" />
<button type="button" id="btn1">Set</button>
</div>
</form>
</body>
</html>

JQuery Thickbox - Can't get it to display

I am using JQuery for the first time today. I can't make it to work (It simple doesnt show up). I want to display inline content using Thickbox (Eventually I will be displaying a PDF in an iframe). I have included all the javascript and css files etc. and referenced them as in code below.
<%# Page Language="C#" AutoEventWireup="true" CodeBehind="Default.aspx.cs" Inherits="JQueryLearning._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>Untitled Page</title>
<script src="Scripts/thickbox.js" type="text/javascript"></script>
<script src="Scripts/thickbox-compressed.js" type="text/javascript"></script>
<script src="Scripts/jquery-1.4.2.min.js" type="text/javascript"></script>
<link href="App_Themes/Theme/Css/thickbox.css" rel="stylesheet" type="text/css" />
</head>
<body>
<form id="form1" runat="server">
<div>
<a href="#TB_inline?height=50&width=300&inlineId=hiddenModalContent"
title="Simple Demo" class="thickbox">Show hidden content.</a>
<div id="hiddenModalContent" style="display: none;">
<div style="text-align: center;">
Hello ThickBox!</div>
</div>
</div>
</form>
</body>
</html>
Am I missing something?
Thanks,
Ali
I think you need to alter the sequence of the script files, otherwise they won't work properly:
<script src="Scripts/jquery-1.4.2.min.js" type="text/javascript"></script>
<script src="Scripts/thickbox.js" type="text/javascript"></script>
<script src="Scripts/thickbox-compressed.js" type="text/javascript"></script>
<link href="App_Themes/Theme/Css/thickbox.css" rel="stylesheet" type="text/css" />
Also: Aren't "thickbox.js" and "thickbox-compressed.js" different compression formats of the same module? In that case, you can omit one of them. If you want to debug inside the js, you need "thickbox.js", otherwise "thickbox-compressed.js" is sufficient.

Jquery Ui DatePicker, attaches to textbox but only works once, then all click events are disabled

<%# 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>
<link rel="stylesheet" href="css/ui-lightness/jquery-ui-1.7.2.custom.css" type="text/css" media="all" />
<script type="text/javascript" src="js/jquery-1.3.2.min.js"></script>
<script type="text/javascript" src="js/jquery-ui-1.7.2.custom.min.js"></script>
<script type="text/javascript">
$(document).ready(function() {
$('#date').datepicker();
});
</script>
</head>
<body>
<%--<form id="form1" runat="server">--%>
<div>
<input type="text" id="date" />
</div>
<%--</form>--%>
</body>
</html>
I've attached a datepicker to a text box and the first time I click it, it works a treat and populates the text box with the current date. It works fine in IE7 Comp mode, Chrome and Firefox. It works once or twice on IE8 but locks the browser up after that. One interesting note is the host operating system is Windows 2008 R2.
Any ideas?
It was a corrupt download that I had somehow grabbed from UI, all sorted.

Resources