English 中文(简体)
不工作的习俗者(asp.net vb)
原标题:CustomValidator not working (asp.net vb)

我第一次使用海关检查员,但似乎没有发射日期。 服务器仪表和刚在Click行动中操作该代码。

现在,我好好几小时! 谁能看一看问题做什么?

The DropDownList in my Code below is populationed using Roles.Get AllRoles()

ASP. NET

<asp:Label ID="lUserRole" runat="server" AssociatedControlID="tUserRole">User Role:</asp:Label>
<asp:DropDownList ID="tUserRole" runat="server" CausesValidation="True">
</asp:DropDownList>

<asp:Label ID="lDateExpire" runat="server" AssociatedControlID="tDateExpire">Date Expire:</asp:Label>
<asp:TextBox ID="tDateExpire" runat="server"></asp:TextBox>
<asp:CustomValidator ID="DateExpireRequired" runat="server"
                ControlToValidate="tDateExpire" ErrorMessage="Date Expire is required for  Users ." OnServerValidate="DateExpireRequired_ServerValidate"
                ToolTip="Date Expire is required for  Users ." CssClass="frmError"></asp:CustomValidator>

CODE BEHIND

    Sub DateExpireRequired_ServerValidate(source As Object, args As System.Web.UI.WebControls.ServerValidateEventArgs)

    If tUserRole.SelectedValue = "User" Then
        If tDateExpire.Text <> "" Then
            args.IsValid = False
        Else
            args.IsValid = True
        End If
    Else
        args.IsValid = True
    End If

End Sub

感谢J。

最佳回答

答案与上文Mendno van den Heuvel的评论一样:

Do you have validateemptytext set to True? I see that you check for an empty string in your event handler, but the event handler won t be run if the bound control s value is empty.

问题回答

您的习惯有效者定义中有Enabled=“false”。 我认为这不利于这一有效者。





相关问题
Anyone feel like passing it forward?

I m the only developer in my company, and am getting along well as an autodidact, but I know I m missing out on the education one gets from working with and having code reviewed by more senior devs. ...

How to Add script codes before the </body> tag ASP.NET

Heres the problem, In Masterpage, the google analytics code were pasted before the end of body tag. In ASPX page, I need to generate a script (google addItem tracker) using codebehind ClientScript ...

Transaction handling with TransactionScope

I am implementing Transaction using TransactionScope with the help this MSDN article http://msdn.microsoft.com/en-us/library/system.transactions.transactionscope.aspx I just want to confirm that is ...

System.Web.Mvc.Controller Initialize

i have the following base controller... public class BaseController : Controller { protected override void Initialize(System.Web.Routing.RequestContext requestContext) { if (...

Microsoft.Contracts namespace

For what it is necessary Microsoft.Contracts namespace in asp.net? I mean, in what cases I could write using Microsoft.Contracts;?

Separator line in ASP.NET

I d like to add a simple separator line in an aspx web form. Does anyone know how? It sounds easy enough, but still I can t manage to find how to do it.. 10x!

热门标签