How do I make a checkbox required on an ASP.NET form?

后端 未结 6 1235
隐瞒了意图╮
隐瞒了意图╮ 2020-11-28 02:51

I\'ve done some searching on this, and I\'ve found several partial answers, however nothing that gives me that warm fuzzy \"this is the right way to do this\". To answer the

6条回答
  •  再見小時候
    2020-11-28 03:46

    Non-javascript way . . aspx page:

     

    Code Behind:

    Protected Sub CustomValidator1_ServerValidate(ByVal source As Object, ByVal args As System.Web.UI.WebControls.ServerValidateEventArgs) Handles CustomValidator1.ServerValidate
        If Not CheckBox1.Checked Then
            args.IsValid = False
        End If
    End Sub
    

    For any actions you might need (business Rules):

    If Page.IsValid Then
       'do logic
    End If 
    

    Sorry for the VB code . . . you can convert it to C# if that is your pleasure. The company I am working for right now requires VB :(

提交回复
热议问题