问题
I am facing an issue with the CalendarExtendar
control hide functionality.
I am displaying the calendar on an image click. It hides if I select a date; but it does not hide when I do not want to select any date from the calendar.
I found this happening only in my application. I tried using the same control in a sample application and it works fine.
Is it because my project has MasterPage
implemented in it?
Please suggest.
回答1:
You can try this You need to handle the onmouseout event. You can do it this way:
http://forums.asp.net/p/1182269/4708411.aspx/1?Re+Calendarextender+and+Lose+Focus+Or+Mouse+Out
Or you could add some javascript (via jQuery) and inject an onmouseout event:
Adding extra functions to an image's onmouseout attribute link Adding extra functions to an image's onmouseout attribute
This is also shown in the forums.asp.net link, but basically, on the onmouseout event you can just set the visibility of the calendar extender to hidden or none.
--------------------------OR CAN TRY BELOW CODE-----------------------------
function calenderShow(sender,args){
var calendar=$find('bi');
calendar._container.onblur=function(){
calendar.hide();
};
}
回答2:
CAN TRY THIS TOO As an option in addition to solutions provided by dash, you may use following decision if you don't want to use ImageButton instead of Image for PopupButton: set OnClientShowing properties on extenders to "hideAnotherOpenedPoups" and add onto a page script below.
// Array of BehaviorIds of each extender for those you use Image as PopupButton
var behaviorIds = ["CalendarExtender1", "CalendarExtender2"];
function hideAnotherOpenedPoups(sender) {
for (var index = 0; index < behaviorIds.length; index++) {
if (behaviorIds[index] !== sender.get_id()) {
var extender = $find(behaviorIds[index]);
if (extender.get_isOpen()) {
extender.hide.call(extender);
}
}
}
}
回答3:
I took one textbox control & one Calender control but after clicking on calender date page post back happen and after that calender was not hiding. I tried all they way but it's never work. Please find the code following.
<asp:TextBox ID="txtFromDateSubmit" runat="server" TabIndex="7" CssClass="calendar" OnTextChanged="txtFromDateSubmit_TextChanged" AutoPostBack="True" MaxLength="12" AutoCompleteType="Disabled"></asp:TextBox>
<asp:CalendarExtender ID="ceBatchDateSubmit" runat="server" Format="dd/MM/yyyy" TargetControlID="txtFromDateSubmit"></asp:CalendarExtender>
After that by mistake i remove TabIndex and it's start working for me. If you guys having same issue and it's matching with my code you can try it.
来源:https://stackoverflow.com/questions/15883797/calendarextender-not-getting-hide-on-clicking-outside-the-calendar