I am using bootstrap datetimepicker (http://eonasdan.github.io/bootstrap-datetimepicker/Installing/).
When I select the date the picker does not hides and I have to click outside to close it.
How to close datetimepicker when date is selected/clicked?
<div class="col-sm-3">
<asp:TextBox ID="date2" class="form-control" runat="server"
onfocus="this.style.backgroundColor='yellow'"
onblur="this.style.backgroundColor='cyan'"/>
<script type="text/javascript">
$(function () {
$('#date2').datetimepicker();
});
</script>
</div>
You can force the datetimepicker to hide itself with the following piece of code.
$('#date2').data("DateTimePicker").hide();
For other functions like hide please consider checking out the documentation.
Related
I don't see any date picker in ASP.NET controls.
Anyone knows how to add it in my my webpage.
I am using VB as my programming language.
Result
I would like to thank everyone who posted the solutions, code and links which helped me to achieve this thread goal. Based on all of the source the below code is the one which works nicely.
Content1
<asp:Content ID="Content1" ContentPlaceHolderID="head" Runat="Server">
<script type="text/javascript" src="http://ajax.aspnetcdn.com/ajax/jQuery/jquery-1.5.1.min.js"></script>
<script type="text/javascript" src="http://ajax.aspnetcdn.com/ajax/jquery.ui/1.8.10/jquery-ui.min.js"></script>
<link href="http://ajax.aspnetcdn.com/ajax/jquery.ui/1.8.10/themes/ui-lightness/jquery-ui.css" rel="stylesheet" type="text/css" />
<script type="text/javascript">
$(function () {
//initialise the datepicker with the date format specified
$(".datepicker").datepicker();
});
</script>
And in
Content2
<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" Runat="Server">
<asp:TextBox runat="server" ID="txt_MyDate" CssClass="datepicker" MaxLength="10" />
Add this inside your [head] Tag.
<link rel="stylesheet" href="http://code.jquery.com/ui/1.11.4/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.4/jquery-ui.js"></script>
and use this jquery function in aspx page inside [script] tag
$(function () {
$("#datepicker").datepicker();
$("#datepicker").change(function () {
$('#btnRefresh').click();
});
and add one textbox for display selected date. and button for getting the date in sever side. like this code
<input type="text" id="datepicker" runat="server" clientidmode="Static" />
<asp:Button ID="btnRefresh" runat="server" onclick="btnRefresh_Click" ClientIDMode="Static"
Text="Refresh" AutoPostback="true" style="display:none;"/>
use this onclick event to do want you want..
You're right, there isn't anything built-in.
Personally I would recommend the jQueryUI datepicker - it's reliable and flexible, and it's javascript based, so it doesn't matter what your server-side language is.
See https://jqueryui.com/datepicker/
Once you've added the required references to jQuery and jQueryUI, in your aspx page, add a script section like this:
<script type="text/javascript" language="javascript">
$(function () {
//initialise the datepicker with the date format specified
$(".datepicker").datepicker();
});
</script>
and then add the "datepicker" class to any textbox controls on the page where you want to use the datepicker:
<asp:TextBox runat="server" ID="txt_MyDate" CssClass="datepicker" MaxLength="10" />
P.S. I can also recommend most of the rest of the jQueryUI package, there are some useful items in there which can speed up your development time and make your apps look nicer and be more usable.
You can implement a datepicker on your page with the help of the Calendar control, using javascript on your page. Try this links for simple methods to do it:
http://www.vbknowledgebase.com/?Id=150&Desc=ASP.Net-DatePicker-using-Calendar-Control
http://www.codedigest.com/Articles/ASPNET/247_DatePicker_Control_in_ASPNet.aspx
http://www.aspsnippets.com/Articles/DateTimePicker-control-for-ASPNet-TextBox-Example.aspx
I can't seem to get my textbox to automatically postback after selecting a date from the bootstrap datetimepicker (Downloaded from here). I stil have to press enter for the event to trigger.
<div class="span3">Date<br />
<div id="datepicker" class="input-append date">
<asp:TextBox ID="txtDate" runat="server" OnTextChanged="txtDate_TextChanged" AutoPostBack="true" />
<span class="add-on">
<i data-time-icon="icon-time" data-date-icon="icon-calendar"></i>
</span>
</div>
</div>
When you select a datetime the input control not lose focus, so the postback not occur. You can force a postback in the event triggered from the datepicker like (not tested):
el.on('changeDate', function(e) {
__doPostBack('<%= txtDate.ClientId %>','');
});
where el is the element on you bind the datetime picker.
Alternatively you can force a blur like:
el.on('changeDate', function(e) {
$('<%= txtDate.ClientId %>').blur();
});
Ref: http://tarruda.github.io/bootstrap-datetimepicker/
I need a calendar to be displayed on a textbox.
This can be achieved using ajaxToolkit: Calendar control.
I can use FilteredTextBoxExtender to ensure that it enters only valid characters.
Also I can use jQuery to ensure that the dates are valid dates only (13/13/20123 is an invalid date).
But is there a better way or ajax control (in the toolkit) for it?
Note: I am looking for a solution using ajax control toolkit. For my project, jQuery-UI is not allowed.
<ajaxToolkit:Calendar runat="server"
TargetControlID="Date1"
CssClass="ClassName"
Format="MMMM d, yyyy"
PopupButtonID="Image1" />
<ajaxToolkit:FilteredTextBoxExtender ID="ftbe" runat="server"
TargetControlID="txtDate"
FilterType="Custom, Numbers"
ValidChars="1234567890/" />
REFERENCE:
http://forums.asp.net/p/1825929/5076051.aspx/1?Re+How+to+disable+future+dates+in+ajax+calendar+extender+
Try Using jQuery UI Datepicker:
<script>
$(function() {
$( "#datepicker" ).datepicker();
});
</script>
<div class="demo">
<p>Date: <input id="datepicker" type="text"></p>
</div>
jQuery UI Datepicker
I'm having trouble getting the values from text box when using ColorBox http://colorpowered.com/colorbox/
I have a form that opens a ColorBox modal dialog.In the modal i have a asp.net textbox and a button when i click the button i'm getting the postback but the value of the textbox is always empty.
<script type="text/javascript">
$(document).ready(function () {
$(".example8").colorbox({ width: "50%", inline: true, href: "#inline_example1" });
});
</script>
....
<form id="form1" runat="server">
Click here</p> <a class='example8'
href="#">Inline HTML</a></p>
<!-- This contains the hidden content for inline calls -->
<div style='display: none'>
<div id='inline_example1' style='padding: 10px; background: #fff;'>
<asp:LinkButton ID="LinkButton1" runat="server" OnClick="LinkButton1_Click">LinkButton</asp:LinkButton><asp:TextBox
ID="TextBox1" runat="server"></asp:TextBox>
</div>
</div>
</form>
Any help will be appreciated.
Thanks.
Try adding the following code to the method call:
$("#colorbox").appendTo('form');
So your code will look like this:
<script type="text/javascript">
$(document).ready(function () {
$(".example8").colorbox({ width: "50%", inline: true, href: "#inline_example1" });
$("#colorbox").appendTo('form');
});
</script>
At least that's what worked for me!
Hope this helps!
This problem occurs because the Colorbox's content is created outside form tag.
To resolve the problem edit the colorbox.cs and edit the method that create the modal.
If you prefer, you can download the file that I changed and fix the problem.
http://www.coyote.inf.br/jquery.colorbox.js
I am trying to implement JQuery in my web page but i am not been able to implement it successfully.
I have a master page
where i added one script for menu bar that is already using jquery hosted by Google
This is coded in master page itself
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.0/jquery.min.js"></script>
Now i want to implement a Jquery to set the css visibility property to true or false.
into my content page of same master page.
<script type="text/javascript">
$(document).ready(function(){
$("#lnkAddMore").click(function(){
alert();
}
);
});
</script>
This html control is under my UpdatePanel.
I dont know why it is not working ?
I am using this control under UpdatePanel.
<input type="button" id="lnkAddMore" value="Add More" />
I tried to use it outside my update
panel it is running successfully but
not in UpdatePanel
I think there is a problem using it with an UpdatePanel
HERE IS MY PAGE SOURCE
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.0/jquery.min.js"></script>
<link href="../../Css/Domain.css" rel="stylesheet" type="text/css" />
<script type="text/javascript">
$(document).ready(function(){
$("#lnkAddMore").click(function(){alert();$('#h').hide(100);});
$('#h').show(100);
});
</script>
<asp:ScriptManager ID="ScriptManager1" runat="server">
</asp:ScriptManager>
<asp:UpdatePanel ID="UpdatePanel1" runat="server">
<ContentTemplate>
<div id="divDomain" runat="server">
<asp:gridview/>
<div style="text-align:right;">
<input type="button" id="lnkAddMore" value="Add More" />
</div>
</div>
</ContentTemplate>
</asp:UpdatePanel>
Do you really have nested <script> tags or was it a typo?
<script type="text/javascript">
<script type="text/javascript">
If that's not a typo, then that's probably the issue.
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.0/jquery.min.js"></script>
<script type="text/javascript">
$(document).ready(function() {
$('#ddmenu > li').bind('mouseover', ddmenu_open)
$('#ddmenu > li').bind('mouseout', ddmenu_timer)
});
$(document).bind('click', ddmenu_close); // do you really want to close on any click?
</script>
I have used two approaches with jQuery and UpdatePanels.
The first is this:
jQuery $(document).ready and UpdatePanels?
The other approach I found on Rick Strahl's blog (http://www.west-wind.com/Weblog/posts/154797.aspx) Which is to do something like this in the code behind:
ScriptManager.RegisterClientScriptBlock(this, typeof(Page), "alertScript",
#" $(document).ready(function(){
$("#lnkAddMore").click(function(){
alert();
}
);
});", true);
Check this out for another example: Problem with ScriptManager.RegisterClientScriptBlock and jQuery in Internet Explorer 8
Also have a look at jQuery's live() event subscriber.
Check that the ID of your button isn't actually getting changed to something like
ctl00_ContentPlaceHolder1_lnkAddMore
since it's residing in a content placeholder for the master page.
If it is, you'd have to adjust your JQuery.
When you're loading code in under an UpdatePanel, try not wrapping it in $(document).ready();. Ready isn't fired on document for AJAX events.