Ich habe ein paar Textfelder, die nur Daten enthalten. Wenn ein Textfeld ein Datum hat und der Benutzer versucht, ohne Eingabe eines Datums in das Textfeld des anderen Datums einzureichen, wird es vor dem Senden gestoppt. Die Art, wie ich dies tun will, ist mit der folgenden JavaScript-Funktion:Erhalten Sie die Kontrolle in Javascript
function ClientValidate(sender, args) {
// Get Both form fields
var txtdate1 = document.getElementById('<%=txtdate1.ClientID%>');
var txtdate2 = document.getElementById('<%=txtdate2.ClientID %>');
// do you client side check to make sure they have something
if (txtdate1.value != '' && txtdate2.value == '') {
args.IsValid = false;
}
else
{
args.IsValid = true;
}
if (txtdate2.value != '' && txtdate1.value == '') {
args.IsValid = false;
}
else {
args.IsValid = true;
}
}
Die Erstellung der Textfelder und das Datum Zeug ist wie folgt.
Dim bttndate1 As New ImageButton
bttndate1.ID = "bttndate1"
Dim txtdate1 As New TextBox
txtdate1.ID = "txtdate1"
txtdate1.Width = 65
Dim calex1 As New AjaxControlToolkit.CalendarExtender
calex1.TargetControlID = "txtdate1"
calex1.Format = "MM/dd/yyyy"
calex1.PopupButtonID = "bttndate1"
'**************** date box2 ***************
Dim bttndate2 As New ImageButton
bttndate2.ID = "bttndate2"
bttndate2.Style.Add("cursor", "pointer")
Dim txtdate2 As New TextBox
txtdate2.ID = "txtdate2"
txtdate2.Width = 65
Dim calex2 As New AjaxControlToolkit.CalendarExtender
calex2.TargetControlID = "txtdate2"
calex2.Format = "MM/dd/yyyy"
calex2.PopupButtonID = "bttndate2"
Hier ist der Validator
Dim custval As New CustomValidator
custval.ID = "ValidPage"
custval.ClientValidationFunction = "ClientValidate"
custval.ErrorMessage = "You Must Enter a 'From' Date and a 'To' Date"
custval.ErrorMessage = "You Must Select a Vendor"
custval.SetFocusOnError = True
custval.ControlToValidate = "txtdate1"
custval.EnableClientScript = True
Mein Problem ist, dass die Javascript nicht die beiden Textfelder findet, weil ich sie in Code erstellen irgendwelche Ideen?
mein Fehler ist immer noch der gleiche. Name 'txtdate1' ist nicht deklariert. – Eric