Wrox Programmer Forums
Go Back   Wrox Programmer Forums > ASP.NET and ASP > ASP.NET 1.0 and 1.1 > ASP.NET 1.1
|
ASP.NET 1.1 As of 10/6/2005, this forum is locked as part of the reorganization described here: http://p2p.wrox.com/topic.asp?TOPIC_ID=35394. No posts have been deleted. Open ongoing discussions from the last week have been moved to either ASP.NET 1.0 and 1.1 Beginners http://p2p.wrox.com/asp-net-1-0-1-1-basics-60/ or ASP.NET 1.0 and 1.1 Professional. http://p2p.wrox.com/forum.asp?FORUM_ID=50. See my sticky post inside for more.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the ASP.NET 1.1 section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old February 27th, 2005, 02:07 PM
Registered User
 
Join Date: Feb 2005
Posts: 8
Thanks: 0
Thanked 0 Times in 0 Posts
Default Disable Calendar postback from javascript

Hi, I have a problem trying to disable the date selection of a calendar control from javascript.

In addition to the Calendar, I have a dropdownlist, some textboxes and an "Update Textboxes" button on the page.

Initially in the original page definition, I have the dropdownlist and the calendar enabled and the button is disabled. When users enter data into the textboxes I have a javascript function that validates the entry and does some additional client side manipulations and when the user exits a textbox the onBlur event does some processing.

The textbox data will be updated to a database when the "Update Textboxes" button is clicked. Therefore, the button is disabled until there is valid data to update, and at that point I want to disable postbacks from the dropdownlist and the calendar, and enable the button postback.

My code works fine for the dropdownlist and the button, but the calendar dates all allow clicking and do a postback. The dropdownlist is grayed out and won't allow a dropdown, the button goes from gray to enabled, and the dates on the calendar go to gray as if the control was disabled, but when you roll the mouse over a date, the pointer changes to a hand and if you click, it performs a postback.

Here's the javascript code:

document.getElementById("DropDownList1").disabled = true; (works fine)
document.getElementById("Calendar1").disabled = true; (only grays)
document.getElementById("btnUpdate").disabled = false; (works fine)

I've also tried setting the Calendar SelectionMode to None, and 0 and "None" and "0" but that doesn't do anything.

I've spent more hours than I care to admit searching Google with combinations of the keywords javascript, asp.net, Calendar, disable, enable, SelectionMode.

I wouldn't be against looping through a list of the days in the calendar and setting each one to disabled, but that also doesn't seem possible.

Any help would be greatly appreciated.

Thank you.

Bob



 
Old February 28th, 2005, 01:09 PM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 1,998
Thanks: 0
Thanked 3 Times in 3 Posts
Default

Override the DayRender event, and within it, I believe that you do:

e.Day.IsSelectable = false

Brian
 
Old February 28th, 2005, 05:35 PM
Registered User
 
Join Date: Feb 2005
Posts: 8
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Hi Brian,
What I need is something on the client side that disables the Calendar control so that a click on any date will not result in a __doPostBack. The DayRender event handler is a server side function.

Right now I am hooking into the client side of the textbox control and if the text in that box is changed I, through a javascript function, enable the Update button (which works) and I disable the DropDownList (which works), and I try to disable the Calendar control, but all the disable on the Calendar does is set all the text, including each day number in the Calendar to a gray, disabled look, but still allows the user to click on the day number and start a postback to the server.

In the javascript function, I can set the visible property of the Calendar to "hide" and it disappears which won't allow the user to effect a postback, but I'm trying to keep the Calendar in view, just not available for clicking.

Thanks for the reply.

Bob

 
Old March 1st, 2005, 01:29 PM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 1,998
Thanks: 0
Thanked 3 Times in 3 Posts
Default

Hey,

Well, if you look at the javascript, you must be able to determine all of the ID's of the javascript links, then yes you could do something like that. If those links don't have any id's, then you might not be able to access it.

Brian
 
Old March 1st, 2005, 04:23 PM
Registered User
 
Join Date: Feb 2005
Posts: 8
Thanks: 0
Thanked 0 Times in 0 Posts
Default

I've found a solution that mostly works. As asp.net renders the calendar control there is a dayRendered event that is fired for each individual day as it is rendered. In this event, I instantiate a new hyperlink control for the day, load it with the day number, backcolor and forecolor of the day that asp.net created, then I delete the control that asp.net created from the cell and then add an ID to the new hyperlink and add it to the cell. In effect, adding an ID to the anchor control that asp.net created.

This then gives me the ability to identify the day in the javascript (from the new ID) and to loop through all the days in the calendar and set the "href" values to "#" rather than "javascript:__doPostBack('Calendar','nnnn')". This keeps the browser from doing the postback, and remains on the current page.

The only remaining problem is that the previous month and next month also have the javascript:__doPostBack and don't seem to have an event when they are rendered to allow me to, in effect, attach an ID so that I can find it on the javascript side when I need to. I may have to just settle for that, or pull the prev and next months off the calendar, or write the whole thing in javascript rather than use the asp.net server control.

Thanks for the replies.

Bob

 
Old March 1st, 2005, 04:37 PM
Registered User
 
Join Date: Feb 2005
Posts: 8
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Thank you Brian. Your replies help point me into the right direction.






Similar Threads
Thread Thread Starter Forum Replies Last Post
avoid postback using ajax in javascript kalyanykk Visual Studio 2005 1 May 30th, 2008 08:16 AM
Calendar Control Postback x_ray ASP.NET 2.0 Basics 1 May 27th, 2007 03:56 AM
How to disable PostBack for a button control? ashraf_gawdat .NET Framework 2.0 7 October 23rd, 2006 01:14 PM
postback issue with drop downlists with javascript emachines Javascript How-To 1 January 6th, 2005 01:49 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.