How can I stop my Calendar control from firing the form validation events?

M

mark4asp

How can I stop my Calendar control from firing the form validation
events?

I have a form containing several controls which have several
validation controls each.

One control is a TextBox where the date is entered. Connected to this
is an image button which launches a popup window containing a calendar
control. The selected value from the calendar is then fed back to the
TextBox.

<asp:TextBox ID="txtDate" runat="server" CausesValidation="true" />
<input ID="lnkDatePopUp" class="imgCalendar" type="image"
onclick="window.open('DatePopUp.aspx?
FormItemName=ctl00$ContentPlaceHolder
$txtDate','cal','width=250,height=225,left=270,top=180')"
Width="100px">

When this happens, the validation warnings are shown for controls
without values. How can I stop this?

For instance:
* can that be done with AJAX?
* should I look for a pure javascript date picker?
* is there are way to achieve my objective by putting the Calendar
control on the same page? (inside a DIV)


The server code for the popup page is shown below:

using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;

public partial class Administration_DatePopUp : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
hid.Value =
((string)Request.QueryString["FormItemName"]).ToString();
}
protected void Calendar1_SelectionChanged(object sender, EventArgs
e)
{
// Define the name and type of the client scripts on the page.
String csname2 = "CalSelectionChange";
Type cstype = this.GetType();

// Get a ClientScriptManager reference from the Page class.
ClientScriptManager cs = Page.ClientScript;

// Check to see if the client script is already registered.
if (!cs.IsClientScriptBlockRegistered(cstype, csname2))
{
string strScript = "<script>window.opener.document.forms(0)." +
hid.Value + ".value = '" +
Calendar1.SelectedDate.ToString("dd/MM/yyyy") +
"';self.close();</script>";
cs.RegisterClientScriptBlock(cstype, csname2, strScript, false);
}
}
}
 
M

Mark Rae

Mark - there's a new AJAX control which looks very swanky to me:

Yes indeed...
I will have to use that one - I can't imagine a javascript control
being anything like as nice as that!

You'd be surprised...

Don't forget that every scroll and click fires a round-trip to the server
and back - a callback is (usually) much less costly than a postback, and
doesn't redraw the entire page obviously, but it's still a hit on the server
which, if you can avoid it, is almost always a good thing to do...
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,756
Messages
2,569,535
Members
45,008
Latest member
obedient dusk

Latest Threads

Top