Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Stopping calendar control postback?

668 views
Skip to first unread message

Tim Goldstein

unread,
Feb 27, 2002, 8:18:50 PM2/27/02
to
I have a page where I want to use the calendar control to select a date, but
don't want the page to do a postback when the date is selected. I have
learned how to fire a client side event when the date is selected, but I
can't figure out how to stop the page from then posting back after the
client event fires?

Tim
[Denver, CO]

Gabor

unread,
Feb 28, 2002, 8:02:04 AM2/28/02
to
Set the autopostback property to false.

"Tim Goldstein" <ti...@ktmarketing.com> wrote in message
news:OijTAW$vBHA.2500@tkmsftngp03...

Tim Goldstein

unread,
Feb 28, 2002, 12:25:30 PM2/28/02
to
Great idea, unfortunately the Calendar object does not have an autopostback
property.

Any other ideas?

Tim
[Denver, CO]

"Gabor" <prof...@elender.hu> wrote in message
news:OmkxRgFwBHA.2020@tkmsftngp02...

Mike Moore (MS)

unread,
Apr 3, 2002, 12:20:35 AM4/3/02
to
I found 5 newsgroup threads on this general question: How to perform
client-side processing of the IE Web Browser Calendar Control.


The answer is that you can override the __doPostBack function to add your
own client code for the calendar control. I'm including a sample below.
However, you are very limited in what you can do.

You might find that using a purely client-side calendar control is a better
solution for you. There are several client-side calendars (including source
code) at http://javascript.internet.com/calendars/ (thanks to Calvin Guo
for this link).

---
The calendar server control was designed to be processed on the server. The
calendar is rendered on the browser as a table. The individual <td> tags do
NOT have their own unique ID's. Therefore, trying to process user activity
on the client is difficult.

For example, to change which day is selected requires changing the styles
of the previously selected <td> tag and that of the newly selected tag.
Since these tags do not have ID's, it is difficult to do this in client
code.

Something you can do is make the entire calendar control dissappear. First,
override the __doPostBack function (this is shown below). Then place this
code in your new post back function (here I call it NewPostBack):
document.getElementById("Calendar1").outerHTML="";

---
Here is a sample which overrides submission of the calendar control.
Instead of submitting, it erases the calendar control. It also allows other
controls to submit.


<%@ Page Language="vb" AutoEventWireup="false" Codebehind="Cal1.aspx.vb"
Inherits="nClientButton.Cal1"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML>
<HEAD>
<title>Cal1</title>
<meta name="GENERATOR" content="Microsoft Visual Studio.NET 7.0">
<meta name="CODE_LANGUAGE" content="Visual Basic 7.0">
<meta name="vs_defaultClientScript" content="JavaScript">
<meta name="vs_targetSchema"
content="http://schemas.microsoft.com/intellisense/ie5">
<script id="clientEventHandlersJS" language="javascript">
<!--
var oldPostBack

function newPostBack(eventTarget, eventArgument) {
if (eventTarget == "Calendar1") {
//If the call to __doPostBack was from Calendar1, then
//erase Calendar1 and do not call the original __doPostBack.
document.getElementById("Calendar1").outerHTML="";
}
else {
//If the call to __doPostBack was NOT from Calendar1, then
//call the original __doPostBack.
oldPostBack(eventTarget, eventArgument);
}
}

function window_onload() {
oldPostBack = __doPostBack;
__doPostBack = newPostBack;
}

//-->
</script>
</HEAD>
<body MS_POSITIONING="GridLayout" language="javascript" onload="return
window_onload()">
<form id="Form1" method="post" runat="server">
<asp:Calendar id="Calendar1" style="Z-INDEX: 101; LEFT: 169px; POSITION:
absolute; TOP: 21px" runat="server"></asp:Calendar>
</form>
</body>
</HTML>


---
Thank you, Mike Moore
Microsoft ASP.NET Developer Support

This posting is provided "AS IS" with no warranties, and confers no rights.

0 new messages