|
Странно работает CustomValidator
#37528288
Ссылка:
Ссылка на сообщение:
Ссылка с названием темы:
Ссылка на профиль пользователя:
|
|
|
|
Вот страница:
1. 2. 3. 4. 5. 6. 7. 8. 9. 10. 11. 12. 13. 14. 15. 16. 17. 18. 19. 20. 21. 22. 23. 24. 25. 26. 27. 28. 29. 30. 31. 32. 33. 34. 35. 36. 37. 38. 39. 40. 41. 42. 43. 44. 45. 46.
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Q.aspx.cs" Inherits="WA2.Q" %>
<%@ Register TagPrefix="ctl" TagName="Timelog" Src="~/TimelogCtl.ascx" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
<div>
<div class="block">
<div class="block_header"><asp:Label ID=lblTimeRecords runat=server></asp:Label><span class="ico ico_01"></span></div>
<div class="block_body">
<div>
<asp:GridView ID=ctlTimeRecords runat=server AutoGenerateColumns=false >
<EmptyDataTemplate>
<p>No entries</p>
</EmptyDataTemplate>
<Columns>
<asp:BoundField HeaderText="Start" DataFormatString="{0:HH:mm}" DataField="TimeBegin" />
<asp:BoundField HeaderText="End" DataFormatString="{0:HH:mm}" DataField="TimeEnd" />
<asp:ButtonField CommandName="Delete" />
</Columns>
</asp:GridView>
</div>
<div>
<asp:DropDownList ID=ctlTimeRecordsFrom runat=server>
</asp:DropDownList>
<asp:DropDownList ID=ctlTimeRecordsTo runat=server>
</asp:DropDownList>
<asp:CustomValidator ID="CustomValidator1" runat="server"
ErrorMessage="CustomValidator" EnableClientScript="False" ForeColor="#FF3300"
onservervalidate="CustomValidator1_ServerValidate"
ValidationGroup="AddRecord"></asp:CustomValidator>
<asp:Button ID=btnTimeRecordsApplyFilter runat=server Text="Apply"
OnClick="btnTimeRecordsApplyFilter_Click" ValidationGroup="AddRecord" />
</div>
</div>
</div>
</div>
</form>
</body>
</html>
Вот код:
1. 2. 3. 4. 5. 6. 7. 8. 9. 10. 11. 12. 13. 14. 15. 16. 17. 18. 19. 20. 21. 22. 23. 24. 25. 26. 27. 28. 29. 30. 31. 32. 33. 34. 35. 36. 37. 38. 39. 40. 41. 42. 43. 44. 45. 46. 47. 48. 49. 50. 51. 52. 53. 54. 55. 56. 57. 58. 59. 60. 61. 62. 63. 64. 65. 66. 67. 68. 69. 70. 71. 72. 73. 74. 75. 76. 77. 78. 79. 80. 81. 82. 83. 84. 85. 86. 87. 88. 89. 90. 91. 92. 93.
using System;
using System.Globalization;
using System.Configuration;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using EmpTime.DataServices;
namespace WA2
{
public partial class Q : System.Web.UI.Page
{
public DateTime TimelogDate
{
get;
set;
}
protected override void OnInit(EventArgs e)
{
base.OnInit(e);
TimelogDate = DateTime.Now;
lblTimeRecords.Text = string.Format("Timelog: {0:f}", TimelogDate);
DateTime dtStart = new DateTime(2011, 11, 11, 0, 0, 0);
while (dtStart.Day == 11)
{
ctlTimeRecordsFrom.Items.Add(new ListItem(string.Format("{0:HH:mm}", dtStart)));
ctlTimeRecordsTo.Items.Add(new ListItem(string.Format("{0:HH:mm}", dtStart)));
dtStart = dtStart.AddMinutes(15);
}
ctlTimeRecordsFrom.Items.Add(new ListItem("24:00"));
ctlTimeRecordsTo.Items.Add(new ListItem("24:00"));
FillData();
}
public void btnTimeRecordsApplyFilter_Click(object sender, EventArgs e)
{
lblTimeRecords.Text = string.Format("Timelog: {0:f}", TimelogDate);
AddRecord();
FillData();
}
public void FillData()
{
DateTime dtFrom = DateTime.MinValue;
DateTime dtTo = DateTime.MaxValue;
dtFrom = new DateTime(TimelogDate.Year, TimelogDate.Month, TimelogDate.Day, 0, 0, 0);
dtTo = new DateTime(TimelogDate.Year, TimelogDate.Month, TimelogDate.Day, 23, 59, 59);
using (EmpTime.DataServices.SBEffectDataModel mdl = new SBEffectDataModel(ConfigurationManager.ConnectionStrings["SqlMainConnectionForDataModel"].ConnectionString))
{
var records = from r in mdl.RegularTimeRecords where r.TimeBegin >= dtFrom && r.TimeEnd <= dtTo select r;
ctlTimeRecords.DataSource = records;
ctlTimeRecords.DataBind();
}
}
public void AddRecord()
{
DateTime dtFrom = DateTime.ParseExact(TimelogDate.ToString("dd.MM.yyyy") + " " + ctlTimeRecordsFrom.SelectedValue, "dd.MM.yyyy HH:mm", CultureInfo.InvariantCulture);
DateTime dtTo = DateTime.ParseExact(TimelogDate.ToString("dd.MM.yyyy") + " " + ctlTimeRecordsTo.SelectedValue, "dd.MM.yyyy HH:mm", CultureInfo.InvariantCulture);
using (EmpTime.DataServices.SBEffectDataModel mdl = new SBEffectDataModel(ConfigurationManager.ConnectionStrings["SqlMainConnectionForDataModel"].ConnectionString))
{
EmpTime.DataServices.RegularTimeRecord r = new RegularTimeRecord()
{
UserLogin = Page.User.Identity.Name,
TimeBegin = dtFrom,
TimeEnd = dtTo
};
mdl.AddToRegularTimeRecords(r);
mdl.SaveChanges();
mdl.AcceptAllChanges();
}
}
protected void CustomValidator1_ServerValidate(object source, ServerValidateEventArgs args)
{
DateTime dtFrom = DateTime.ParseExact(TimelogDate.ToString("dd.MM.yyyy") + " " + ctlTimeRecordsFrom.SelectedValue, "dd.MM.yyyy HH:mm", CultureInfo.InvariantCulture);
DateTime dtTo = DateTime.ParseExact(TimelogDate.ToString("dd.MM.yyyy") + " " + ctlTimeRecordsTo.SelectedValue, "dd.MM.yyyy HH:mm", CultureInfo.InvariantCulture);
if (dtTo <= dtFrom)
args.IsValid = false;
else
args.IsValid = true;
}
}
}
Кликаю на кнопку, CustomValidator1_ServerValidate выполняется, выполнение сваливается на ветку args.IsValid = false. Но почему после этого начинает выполняться btnTimeRecordsApplyFilter_Click?????
|
|
|