我有用户控件,我在其中编写了自定义验证,它检查文本框中输入的数据是否正确位置。单击按钮单击我检查了 (page.IsValid) 位,
即使验证失败,它也会重新加载添加用户控件的整个页面
自定义验证看起来像;
<asp:CustomValidator id="CustomValidator1" runat="server" Width="102px" Style="margin-left:37px !important" OnServerValidate="TextValidate" ControlToValidate="txtLocationId" ErrorMessage="Incorrect Location.">
</asp:CustomValidator>
在 UserControl.aspx.cs 中:->
protected void TextValidate(object source, ServerValidateEventArgs args)
{
string value = string.Empty;
dbconfig.conDatabase2.Open();
SqlCommand cmdsqlcmd = new SqlCommand();
cmdsqlcmd.CommandType = CommandType.Text;
string locID = args.Value.ToString();
cmdsqlcmd.CommandText = "";
cmdsqlcmd.Connection = dbconfig.conDatabase2;
Object ob = cmdsqlcmd.ExecuteScalar();
if (ob == null)
{
args.IsValid = false;
}
else
{
args.IsValid = true;
}
}
在按钮单击:
protected void goButton_OnClick(object sender, EventArgs e) { if (Page.IsValid) { 代码在这里... } }
在 aspx 页面中:
<%@ Register Src="UserControl/UserControlFilter.ascx" TagName="UserControlFilter"
TagPrefix="uc1" %>
<html>
<body>
<form id="form1" runat="server">
<AjaxToolkit:ToolkitScriptManager ID="ToolkitScriptManager1" runat="server">
</AjaxToolkit:ToolkitScriptManager>
<asp:Timer ID="Timer1" runat="server" OnTick="Timer1_Tick" Interval="300000">
</asp:Timer>
<asp:UpdatePanel ID="UpdatePanel1" UpdateMode="Conditional" runat="server">
<Triggers>
<asp:AsyncPostBackTrigger ControlID="Timer1" EventName="Tick" />
</Triggers>
<ContentTemplate>
<div class="locadetail" id="bigtrends" style="border-radius:5px;width: 884px; z-index: 100; border-width: 1px;
margin: 10px; height: 398px !important; float: left; background-color: #fff !important;">
</div>
</ContentTemplate>
</asp:UpdatePanel>
</form>
</body>
</html>
如果我在某个地方出错了,请告诉我
谢谢