N
Ned Balzer
I posted this this morning but it never went through, so I am trying
again -- apologies for the duplication if so.
I need to validate several checkboxes on an asp.net 2.0 page. I don't
need to validate that they are checked; instead, I am trying to
prevent potential SQL or code injection via checkbox controls. These
checkboxes are inside a formview.
I found examples (e.g at http://msdn2.microsoft.com/en-us/library/aa479013.aspx)
of how to validate that at least one in a group of checkboxes, or one
of a checkboxlist, has been checked, but my requirement is a little
different.
What I'd like to do is write a server side and client side functions
that several customvalidation controls can share. So the function
would determine which checkbox control is failing validation and
respond appropriately.
The example code looks like this:
<script runat="server">
Sub CustomValidator1_ServerValidate(source As Object, _
args As ServerValidateEventArgs)
args.IsValid = (CheckBox1.Checked = True)
End Sub
Sub Button1_Click(sender As Object, e As EventArgs)
If Page.IsValid Then
Label1.Text = "Thank you for your donation!"
Else
Label1.Text = ""
End If
End Sub
</script>
....
<asp:CheckBox id="CheckBox1" runat="server"
Text="Donate $10"></asp:CheckBox>
<asp:CustomValidator id="CustomValidator1"
runat="server" ErrorMessage="Please donate $10"
OnServerValidate="CustomValidator1_ServerValidate">
</asp:CustomValidator>
The problem is that the checkbox control is referenced in Sub
CustomValidator1_ServerValidate by its ID, but I'd like the server
side validation subroutine to handle any number of different
checkboxes.
Is it possible to determine which checkbox is failing validation by
examining either of the two parameters passed to Sub
CustomValidator1_ServerValidate? (either "source" or
"ServerValidateEventArgs")?
Thanks.
-- Ned Balzer
again -- apologies for the duplication if so.
I need to validate several checkboxes on an asp.net 2.0 page. I don't
need to validate that they are checked; instead, I am trying to
prevent potential SQL or code injection via checkbox controls. These
checkboxes are inside a formview.
I found examples (e.g at http://msdn2.microsoft.com/en-us/library/aa479013.aspx)
of how to validate that at least one in a group of checkboxes, or one
of a checkboxlist, has been checked, but my requirement is a little
different.
What I'd like to do is write a server side and client side functions
that several customvalidation controls can share. So the function
would determine which checkbox control is failing validation and
respond appropriately.
The example code looks like this:
<script runat="server">
Sub CustomValidator1_ServerValidate(source As Object, _
args As ServerValidateEventArgs)
args.IsValid = (CheckBox1.Checked = True)
End Sub
Sub Button1_Click(sender As Object, e As EventArgs)
If Page.IsValid Then
Label1.Text = "Thank you for your donation!"
Else
Label1.Text = ""
End If
End Sub
</script>
....
<asp:CheckBox id="CheckBox1" runat="server"
Text="Donate $10"></asp:CheckBox>
<asp:CustomValidator id="CustomValidator1"
runat="server" ErrorMessage="Please donate $10"
OnServerValidate="CustomValidator1_ServerValidate">
</asp:CustomValidator>
The problem is that the checkbox control is referenced in Sub
CustomValidator1_ServerValidate by its ID, but I'd like the server
side validation subroutine to handle any number of different
checkboxes.
Is it possible to determine which checkbox is failing validation by
examining either of the two parameters passed to Sub
CustomValidator1_ServerValidate? (either "source" or
"ServerValidateEventArgs")?
Thanks.
-- Ned Balzer