I've been searching since yesterday for a solution to this silly problem. I have an ASP app on VS2005 with this one content page having a placeholder on it. I then create a table dynamically and there after a few controls in the table, according to a dataset
created earlier. depending on the dataset record, I different input controls in each cell of the table.
The problem is with the textbox that has to carry a date. I create the textbox, then the
MaskedEditExtender, then the MaskedEditValidator and then a
CalendarExtender. The date format is set as yyyy/MM/dd and the culture as en-ZA (english, South Africa). All values displays correctly and the format is correct, but it does not validate. I've tried doing this in design time, incase the problem
is with the dynamically created controls, but it still does the same. I will appreciate if anyone can help!
Regards,
CK
Code:
' Create textbox
Dim txt1
As
New TextBox
If IsDBNull(DSTableControl.Tables("DSTable").Rows(a).Item("tbValue"))
= True
Then
txt1.Text = DSTableControl.Tables("DSTable").Rows(a).Item("tbValue")
& vbNullString
Else
txt1.Text = Format(CDate(DSTableControl.Tables("DSTable").Rows(a).Item("tbValue")),
"yyyy/MM/dd")
End
If
txt1.ID = "CalTxt" & DSTableControl.Tables("DSTable").Rows(a).Item("tbControlID")
'Create MaskedEditExtender
Dim CalMask
As
New AjaxControlToolkit.MaskedEditExtender
CalMask.ID = "Mask" & DSTableControl.Tables("DSTable").Rows(a).Item("tbControlID")
"en-ZA"
'create MaskedEditValidator
Dim CalMaskVal
As
New AjaxControlToolkit.MaskedEditValidator
CalMaskVal.ID = "CalMaskVal" & DSTableControl.Tables("DSTable").Rows(a).Item("tbControlID")
CalMaskVal.ControlExtender = CalMask.ID
CalMaskVal.ControlToValidate = txt1.ID
CalMaskVal.InvalidValueMessage =
"*"
CalMaskVal.InvalidValueBlurredMessage =
"*"
CalMaskVal.TooltipMessage = "Input a date as " & CalMask.Mask
CalMaskVal.IsValidEmpty =
True
CalMaskVal.Enabled =
True
'create CalendarExtender
Dim CalExt
As
New AjaxControlToolkit.CalendarExtender
CalExt.ID = "CalExt" & DSTableControl.Tables("DSTable").Rows(a).Item("tbControlID")
I've also tried to change the format to yy/MM/dd, dd/MM/yy or dd/MM/yyyy and also the culture name, as well as my own regional settings and nothing seems to work!?! It seems that something is needed by either the maskedEditExtender or validator...
I have built a test application same to yours to create the Validation at server side, but it can work well. Please refer to the code.
Protected Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs)
Dim txt1 As New TextBox
txt1.ID = "txt1"
Dim CalMask As New AjaxControlToolkit.MaskedEditExtender
CalMask.ID = "CalMask"
CalMask.TargetControlID = "txt1"
CalMask.MaskType = AjaxControlToolkit.MaskedEditType.Date
CalMask.Mask = "9999/99/99"
CalMask.MessageValidatorTip = True
CalMask.OnFocusCssClass = "MaskedEditFocus"
CalMask.OnInvalidCssClass = "MaskedEditError"
CalMask.ErrorTooltipEnabled = False
CalMask.UserDateFormat = AjaxControlToolkit.MaskedEditUserDateFormat.YearMonthDay
CalMask.ClearTextOnInvalid = False
CalMask.MessageValidatorTip = False
CalMask.CultureName = "en-ZA"
Dim CalMaskVal As New AjaxControlToolkit.MaskedEditValidator
CalMaskVal.ID = "CalMaskVal"
CalMaskVal.ControlExtender = CalMask.ID
CalMaskVal.ControlToValidate = txt1.ID
CalMaskVal.InvalidValueMessage = "*"
CalMaskVal.InvalidValueBlurredMessage = "*"
CalMaskVal.TooltipMessage = "Input a date as " + CalMask.Mask
CalMaskVal.IsValidEmpty = True
Dim CalExt As New AjaxControlToolkit.CalendarExtender
CalExt.ID = "CalExt"
CalExt.TargetControlID = txt1.ID
CalExt.Format = "yyyy/MM/dd"
Me.form1.Controls.Add(txt1)
Me.form1.Controls.Add(CalMask)
Me.form1.Controls.Add(CalMaskVal)
Me.form1.Controls.Add(CalExt)
End Sub
What my suggestion is checking whether the four Controls are in the same NamingContainer of the control tree. Note that the controls should be added every time after the post back.
Best regards,
Zhi-Qiang Ni
Microsoft Online Community Support
Please remember to click “Mark as Answer” on the post that helps you, and to click “Unmark as
Answer” if a marked post does not actually answer your question.
Thanks for the reply. I've been wiating for someone to reply since this is the only outstanding issue on my web app.
I took your code as-is, pasted it into a new blank site's default page load sub and believe it, it still shows the date as invalid, even if I pick it from the calendarExtender. the only thing I added was a scriptmanager...
Regarding your last suggestion, the table is created in a static placeholder and all 4 controls in one cell of the table. The sub that created them is called from the load event, so they are created on every postback.
I the tried creating the same controls in design time and it worked &(#*$&(@!! It seemed like I'm missing someting stupid, but i couldn't put my finger on it. I then started to comment out some of the lines one by one to see which line is causing the trouble.
It seemed to be the UserDateFormat property. So it validates, but it is saved incorrectly to the database ( 2008/11/17 is saved as 1900/01/11). I will just add some formating to the update string and hopefully it will do the trick.
My question then is why the UserDateFormat property will cause this problem as all the date formats are the same?
I dug into the original design code of the MaskedEditExtender(MaskedEditBehavior.js file) and the MaskedEditValidator(MaskedEditValidator.cs file), and found out maybe it is caused by the ‘careless’ coding of it.
In the MaskedEditBehavior’s get_CultureDateFormat function, it get the input UserDateFormat value and return to a short format value such as “YMD”,”MYD” and so on.
, get_CultureDateFormat : function()
{
var ret = this._CultureDateFormat;
switch (this.get_UserDateFormat())
{
case AjaxControlToolkit.MaskedEditUserDateFormat.DayMonthYear:
{
ret = "DMY";
break;
}
case AjaxControlToolkit.MaskedEditUserDateFormat.DayYearMonth:
{
ret = "DYM";
break;
}
case AjaxControlToolkit.MaskedEditUserDateFormat.MonthDayYear:
{
ret = "MDY";
break;
}
case AjaxControlToolkit.MaskedEditUserDateFormat.MonthYearDay:
{
ret = "MYD";
break;
}
case AjaxControlToolkit.MaskedEditUserDateFormat.YearDayMonth:
{
ret = "YDM";
break;
}
case AjaxControlToolkit.MaskedEditUserDateFormat.YearMonthDay:
{
ret = "YMD";
break;
}
}
return ret;
}
But in the MaskedEditValidator’s OnPreRender function, the ‘DateFormat’ attribute has been assigned to the “ToString” value rather than the short one.
Please remember to click “Mark as Answer” on the post that helps you, and to click “Unmark as
Answer” if a marked post does not actually answer your question.
CKdP
Member
25 Points
18 Posts
MaskedEditValidator not validating date in textbox
Nov 12, 2008 07:34 AM|LINK
Hi All
I've been searching since yesterday for a solution to this silly problem. I have an ASP app on VS2005 with this one content page having a placeholder on it. I then create a table dynamically and there after a few controls in the table, according to a dataset created earlier. depending on the dataset record, I different input controls in each cell of the table.
The problem is with the textbox that has to carry a date. I create the textbox, then the MaskedEditExtender, then the MaskedEditValidator and then a CalendarExtender. The date format is set as yyyy/MM/dd and the culture as en-ZA (english, South Africa). All values displays correctly and the format is correct, but it does not validate. I've tried doing this in design time, incase the problem is with the dynamically created controls, but it still does the same. I will appreciate if anyone can help!
Regards,
CK
Code:
' Create textbox
Dim txt1 As New TextBox If IsDBNull(DSTableControl.Tables("DSTable").Rows(a).Item("tbValue")) = True Then txt1.Text = DSTableControl.Tables("DSTable").Rows(a).Item("tbValue") & vbNullString Else txt1.Text = Format(CDate(DSTableControl.Tables("DSTable").Rows(a).Item("tbValue")), "yyyy/MM/dd") End If txt1.ID = "CalTxt" & DSTableControl.Tables("DSTable").Rows(a).Item("tbControlID") 'Create MaskedEditExtender Dim CalMask As New AjaxControlToolkit.MaskedEditExtender CalMask.ID = "Mask" & DSTableControl.Tables("DSTable").Rows(a).Item("tbControlID")CalMask.TargetControlID = txt1.ID
CalMask.Mask =
"9999/99/99"CalMask.MessageValidatorTip =
TrueCalMask.OnFocusCssClass =
"MaskedEditFocus"CalMask.OnInvalidCssClass =
"MaskedEditError"CalMask.MaskType = AjaxControlToolkit.MaskedEditType.Date
CalMask.ErrorTooltipEnabled =
FalseCalMask.UserDateFormat = AjaxControlToolkit.MaskedEditUserDateFormat.YearMonthDay
CalMask.ClearTextOnInvalid =
FalseCalMask.MessageValidatorTip =
FalseCalMask.CultureName =
"en-ZA" 'create MaskedEditValidator Dim CalMaskVal As New AjaxControlToolkit.MaskedEditValidator CalMaskVal.ID = "CalMaskVal" & DSTableControl.Tables("DSTable").Rows(a).Item("tbControlID")CalMaskVal.ControlExtender = CalMask.ID
CalMaskVal.ControlToValidate = txt1.ID
CalMaskVal.InvalidValueMessage =
"*"CalMaskVal.InvalidValueBlurredMessage =
"*" CalMaskVal.TooltipMessage = "Input a date as " & CalMask.MaskCalMaskVal.IsValidEmpty =
TrueCalMaskVal.Enabled =
True 'create CalendarExtender Dim CalExt As New AjaxControlToolkit.CalendarExtender CalExt.ID = "CalExt" & DSTableControl.Tables("DSTable").Rows(a).Item("tbControlID")CalExt.TargetControlID = txt1.ID
CalExt.Format =
"yyyy/MM/dd" ' Add to cell.Table1.Rows(DSTableControl.Tables _
("DSTable").Rows(a).Item("tbRow") + 1).Cells(DSTableControl.Tables _("DSTable").Rows(a).Item("tbCol")).Controls.Add(txt1)Table1.Rows(DSTableControl.Tables _
(
"DSTable").Rows(a).Item("tbRow") + 1).Cells(DSTableControl.Tables _ ("DSTable").Rows(a).Item("tbCol")).Controls.Add(CalMask)Table1.Rows(DSTableControl.Tables _
("DSTable").Rows(a).Item("tbRow") + 1).Cells(DSTableControl.Tables _("DSTable").Rows(a).Item("tbCol")).Controls.Add(CalMaskVal)Table1.Rows(DSTableControl.Tables _
("DSTable").Rows(a).Item("tbRow") + 1).Cells(DSTableControl.Tables _(
"DSTable").Rows(a).Item("tbCol")).Controls.Add(CalExt)CKdP
Member
25 Points
18 Posts
Re: MaskedEditValidator not validating date in textbox
Nov 13, 2008 04:44 AM|LINK
Hi All
I've also tried to change the format to yy/MM/dd, dd/MM/yy or dd/MM/yyyy and also the culture name, as well as my own regional settings and nothing seems to work!?! It seems that something is needed by either the maskedEditExtender or validator...
Your help will be much appreciated!!!
Regards,
CK
Zhi-Qiang Ni...
All-Star
33491 Points
2952 Posts
Microsoft
Re: MaskedEditValidator not validating date in textbox
Nov 17, 2008 06:19 AM|LINK
Hi,
What my suggestion is checking whether the four Controls are in the same NamingContainer of the control tree. Note that the controls should be added every time after the post back.I have built a test application same to yours to create the Validation at server side, but it can work well. Please refer to the code.
Best regards,
Zhi-Qiang Ni
Please remember to click “Mark as Answer” on the post that helps you, and to click “Unmark as
Answer” if a marked post does not actually answer your question.
CKdP
Member
25 Points
18 Posts
Re: MaskedEditValidator not validating date in textbox
Nov 17, 2008 07:33 AM|LINK
Hi Zhi-Qiang
Thanks for the reply. I've been wiating for someone to reply since this is the only outstanding issue on my web app.
I took your code as-is, pasted it into a new blank site's default page load sub and believe it, it still shows the date as invalid, even if I pick it from the calendarExtender. the only thing I added was a scriptmanager...
Regarding your last suggestion, the table is created in a static placeholder and all 4 controls in one cell of the table. The sub that created them is called from the load event, so they are created on every postback.
I the tried creating the same controls in design time and it worked &(#*$&(@!! It seemed like I'm missing someting stupid, but i couldn't put my finger on it. I then started to comment out some of the lines one by one to see which line is causing the trouble. It seemed to be the UserDateFormat property. So it validates, but it is saved incorrectly to the database ( 2008/11/17 is saved as 1900/01/11). I will just add some formating to the update string and hopefully it will do the trick.
My question then is why the UserDateFormat property will cause this problem as all the date formats are the same?
regards
CK
Zhi-Qiang Ni...
All-Star
33491 Points
2952 Posts
Microsoft
Re: MaskedEditValidator not validating date in textbox
Nov 17, 2008 09:25 AM|LINK
Hi,
I dug into the original design code of the MaskedEditExtender(MaskedEditBehavior.js file) and the MaskedEditValidator(MaskedEditValidator.cs file), and found out maybe it is caused by the ‘careless’ coding of it.
In the MaskedEditBehavior’s get_CultureDateFormat function, it get the input UserDateFormat value and return to a short format value such as “YMD”,”MYD” and so on.
But in the MaskedEditValidator’s OnPreRender function, the ‘DateFormat’ attribute has been assigned to the “ToString” value rather than the short one.Then every Validation would failed when using the UserDateFormat property.
I recommend you report this issue to the IssueTracker of the CodePlex Team to get more help and stop using this property for a while.
Please let me know the result.
Best regards,
Zhi-Qiang Ni
Please remember to click “Mark as Answer” on the post that helps you, and to click “Unmark as
Answer” if a marked post does not actually answer your question.
CKdP
Member
25 Points
18 Posts
Re: MaskedEditValidator not validating date in textbox
Nov 17, 2008 09:54 AM|LINK
Thanks for your help!
Will do so.
cheers
CK