D
Dmitry Duginov
Hi,
I need to clear the value in one textbox (dataEta) when user is changing the
value in another one (dataPickUpDate)
The following code works fine for typing in the textbox and cut-n-pasting
into it (onkeypress and onchange events fire)
protected void FormView1_DataBound(object sender, EventArgs e)
{
if (FormView1.CurrentMode == FormViewMode.Edit)
{
TextBox pickuptextbox =
(TextBox)FormView1.FindControl("dataPickUpDate");
TextBox ETAtextbox = (TextBox)FormView1.FindControl("dataEta");
pickuptextbox.Attributes.Add("onchange",
String.Format("clearETA('{0}');", ETAtextbox.ClientID));
pickuptextbox.Attributes.Add("onkeypress",
String.Format("clearETA('{0}');", ETAtextbox.ClientID));
}
}
....
<script language=javascript type="text/javascript">
function clearETA(TextBox)
{
var textboxETA = document.getElementById(TextBox);
if (textboxETA!=null)
textboxETA.value='';
}
</script>
However, user also can select the new value using calendar pop-up control:
<asp:TextBox runat="server" ID="dataEta"
Text='<%# Bind("Eta", "{0:d}") %>' />
<asp:ImageButton ID="cal_dataPickUpDate" runat="server"
OnClientClick = "javascript:showCalendarControl(this.previousSibling);return
false;"/>
Of course, in this case neither onchange nor onkeypress fires.
How would I ensure that clearETA() javascript function called when the user
selects the date from the calendar pop-up? I am reluctant to make changes in
showCalendarControl() because it is used application-wide and usually this
extra functionality is not required. What are my options?
D.
I need to clear the value in one textbox (dataEta) when user is changing the
value in another one (dataPickUpDate)
The following code works fine for typing in the textbox and cut-n-pasting
into it (onkeypress and onchange events fire)
protected void FormView1_DataBound(object sender, EventArgs e)
{
if (FormView1.CurrentMode == FormViewMode.Edit)
{
TextBox pickuptextbox =
(TextBox)FormView1.FindControl("dataPickUpDate");
TextBox ETAtextbox = (TextBox)FormView1.FindControl("dataEta");
pickuptextbox.Attributes.Add("onchange",
String.Format("clearETA('{0}');", ETAtextbox.ClientID));
pickuptextbox.Attributes.Add("onkeypress",
String.Format("clearETA('{0}');", ETAtextbox.ClientID));
}
}
....
<script language=javascript type="text/javascript">
function clearETA(TextBox)
{
var textboxETA = document.getElementById(TextBox);
if (textboxETA!=null)
textboxETA.value='';
}
</script>
However, user also can select the new value using calendar pop-up control:
<asp:TextBox runat="server" ID="dataEta"
Text='<%# Bind("Eta", "{0:d}") %>' />
<asp:ImageButton ID="cal_dataPickUpDate" runat="server"
OnClientClick = "javascript:showCalendarControl(this.previousSibling);return
false;"/>
Of course, in this case neither onchange nor onkeypress fires.
How would I ensure that clearETA() javascript function called when the user
selects the date from the calendar pop-up? I am reluctant to make changes in
showCalendarControl() because it is used application-wide and usually this
extra functionality is not required. What are my options?
D.