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);
}
}
}
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);
}
}
}