Custom calendar control vanishes on postback in ASP

After creating a custom calendar control that works smoothly for the most part, I encountered an issue. Whenever it is posted, the control disappears even when the user is still hovering over it. I want users to be able to change months, dates, or anything else without the divCalendarDropDown disappearing unexpectedly. Any suggestions on how to fix this?

<%@ Control Language="C#" AutoEventWireup="true" CodeBehind="DateTimePickerObject.ascx.cs" Inherits="DateTimePicker.DateTimePickerObject" %>

<script type="text/javascript">
    var canHover = true;

    var calendarControl = $(".calendarControl"), flip = $(".divCalendarDropDown"),
    state = $.cookie("ToggleStatus");

    function setCalendarVisibility(className) {
        if (canHover) {
            var dropDown = document.getElementById("divCalendarDropDown");
            dropDown.className = className;
        }
    };
    function OnClick_Calendar() {
        var dropDown = document.getElementById("divCalendarDropDown");
        if (dropDown.style.height >= 1) {
            canHover = true;
            dropDown.className = 'divHidden';
        }
        else {
            canHover = false;
            dropDown.className = 'divNormal';
        };
    };
</script>
<!-- CSS styles go here -->
</style>
<div class="calendarControl">
    <asp:TextBox runat="server" ID="textboxCalendar" onMouseOver="setCalendarVisibility('divNormal');" onMouseOut="setCalendarVisibility('divHidden');" onBlur="textboxCalendar_OnBlur()" ReadOnly="True" CssClass="textboxCalendar"></asp:TextBox>
    <span id="spanCalendar" class="spanCalendar"><img id="imgCalendar" src="calendar.png" alt="Calendar" class="imgCalendar" onclick="OnClick_Calendar();"/></span>
    <div id="divCalendarDropDown" onMouseOver="setCalendarVisibility('divNormal');" onMouseOut="setCalendarVisibility('divHidden');">
        <asp:Calendar runat="server" ID="calendarMain" OnSelectionChanged="calendarMain_SelectionChanged" CssClass="calendar" NextPrevFormat="CustomText" NextMonthText=">>" PrevMonthText="<<" SelectionMode="Day" >
            <NextPrevStyle CssClass="nextPrevStyle" />
            <DayHeaderStyle CssClass="dayHeaderStyle" />
            <DayStyle CssClass="dayStyle" />
            <OtherMonthDayStyle CssClass="otherMonthDayStyle" />
            <SelectedDayStyle CssClass="selectedDayStyle" />
            <TitleStyle CssClass="titleStyle" />
            <TodayDayStyle CssClass="todayDayStyle" />
            <WeekendDayStyle CssClass="weekendDayStyle" />
        </asp:Calendar>
    </div>
</div>

Answer №1

Unfortunately, I am unable to leave this as a comment at the moment.

It seems like you cannot prevent the postback to the server with the asp:Calendar control. One suggestion would be to assign a default class to your DIV "divCalendarDropDown" - such as:

<div id="divCalendarDropDown" class="divNormal" onMouseOver="setCalendarVisibility('divNormal');" onMouseOut="setCalendarVisibility('divHidden');">

If that solution does not work, you could consider adding another action to the DIV element, like onblur or onload - for example:

<div id="divCalendarDropDown" onload="setCalendarVisibility('divNormal');" onMouseOver="setCalendarVisibility('divNormal');" onMouseOut="setCalendarVisibility('divHidden');">

I hope these suggestions prove to be helpful! JM

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

How can I loop the keyframe animation across various elements of an SVG file simultaneously?

After creating an animation using CSS and SVG, I am experiencing different parts of it animating in and out. My goal is to have the animation start from the top once it's finished. There are multiple keyframes involved since I'm animating variou ...

What are the steps to successfully submit my form once all the validation requirements have been met?

I successfully completed the validation process, but I am encountering an issue when trying to submit the form. An error message pops up indicating that there is an error related to a specific field (e.g., special characters being used). However, even when ...

Find the current location on Google maps and center it

Is it possible to easily center the map on the current location? I have been attempting to achieve this feature for a while now, but unfortunately, I have not found a reliable solution yet. ...

Signal for a complete 360 degree rotation of an image

Looking to enhance my 360 image rotator with an indicator that fades out after the first image. I added this function to the end of my 360.js: (function(){ if( $('#first').css('visibility','hidden')) { $('#rotat ...

Leveraging Javascript to retrieve input values

Here is my HTML code snippet: <li id='category-10'> <label class="selectit"> <input value="10" type="checkbox" name="post_category[]" id="in-category-10" /> Developmental </label> </li> Below is my JavaScript funct ...

Unraveling the .ASPXAUTH Cookie while ensuring protection with validation

After spending a considerable amount of time attempting to unravel the mysteries of the ASP .ASPXAUTH cookie and decrypting it using PHP, I find myself facing a monumental challenge that must be conquered for important reasons. Despite successfully extract ...

`After the initial instance, the menu title will be altered.`

I have a responsive menu using Bootstrap. When the menu is collapsed, I want it to display the name of the page, and when it is open, I want it to show "Menu." Currently, I have named it "Watch the Trailer" (so let's assume that we are on that page). ...

Mapping a bar chart on a global scale

Are there any methods available to create bar charts on a world map? The world map could be depicted in a 3D view resembling a Globe or in a 2D format. It should also have the capability to zoom in at street level. Does anyone have suggestions or examples ...

"Step-by-step guide for remotely accessing SAS on Unix server from a Windows Server using .NET technology

I recently developed a basic asp.net code using VS2010 that can interact with a SAS program on a Unix server via SAS/IOM. The code functions properly when deployed on my local IIS. However, when I attempted to deploy the web application on a Windows Server ...

Is it possible to use a component created in the newest version of Angular in apps developed with older versions of Angular?

I am interested in developing a component using the most recent version of Angular. However, my intention is to use this component in two distinct Angular applications - one created with Angular 6 and another with Angular 10. Is it feasible to achieve this ...

Encountering an issue during the user login or registration process

Issue: I've been facing a challenge with storing user signup and login information in my database and redirecting the user to another page using the useNavigate Hook. Every time I try clicking on the signup or login button on the frontend, it fails an ...

Issue with background image not displaying properly in Safari versions 4 and 5

I'm having trouble getting my logo to display in Safari 4/5. Does anyone know what could be causing this issue? Here is the CSS code I'm using (before compilation): background: url("../img/logos%20and%20icons/logoLrg.png") no-repeat scroll 0 0 ...

I'm looking to use node.js to post an image on my blog

I am currently in the process of setting up a new blog using node.js. Everything is working smoothly on my local setup, but I am facing an issue when it comes to adding images to my articles. Despite utilizing bootstrap for input display, I am unable to sa ...

Using Jquery to switch between different CSS styles

I'm currently working with a jQuery code that is functioning properly. $(window).load(function() { $('.menuBtn').click(function(e) { e.preventDefault(); (this.classList.contains('is-active') === true) ? this.c ...

MAUI can exclusively be utilized within the Visual Studio environment

Currently, I am working with MAUI and .NET 7.0 in Visual Studio. After creating an example project and running the code through NuGet Manager, everything seemed to work fine within the IDE. However, when attempting to run the executable file directly from ...

You have exceeded the maximum number of Facebook application requests allowed (#4)

My goal is to create a dynamic "social wall" on a website by pulling posts from a specific Facebook page using the Facebook API. Instead of utilizing any Facebook SDK, I am making cURL calls with the URLs directly. To fetch the posts, I rely on Javascript ...

MongoJS Node findOne query inaccurately returns empty result set

Utilizing MongoJS: https://github.com/mafintosh/mongojs Retrieves all data Returns an empty array</p> The database contains the data I am looking for. I've also tried searching using a different key (such as name). Why is it unable to locate ...

using CSS to position elements that are generated dynamically

Hey there, I'm facing a little issue with my elements. These elements are being generated dynamically and I'd like to display them in a 4 column layout. The challenge is that they arrive separately and I can't simply wrap them in a div and u ...

Issue with Chrome not triggering onMouseEnter event when an element blocking the cursor disappears in React

Important Note: This issue seems to be specific to Chrome Currently, React does not trigger the onMouseEnter event when a blocking element disappears. This behavior is different from standard JavaScript events and even delegated events. Below is a simpli ...

The onreadystatechange function is not triggering

For some reason, the onreadystatechange callback function is not triggering in asynchronous mode. After testing the post request in synchronous mode, it seems that the post itself is functioning correctly (the testing code used for synchronous mode has b ...