Hi,
Based on my understanding, your question is how to use validator to require
either one of two textboxes gets filled when submitted.
I think you can use a CustomValidator to do this:
WebForm:
<script type="text/javascript" language="javascript">
function check1(source, arguments)
{
arguments.IsValid = true;
if (form1.TextBox1.value == '' && form1.TextBox2.value == '')
arguments.IsValid = false;
}
</script>
</HEAD>
<body>
<form id="form1" runat="server">
<div>
<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
<asp:TextBox ID="TextBox2" runat="server"></asp:TextBox>
<asp:Button ID="Button1" runat="server" Text="Button"
OnClick="Button1_Click" />
<asp:CustomValidator ID="CustomValidator1" runat="server"
ErrorMessage="CustomValidator" ClientValidationFunction="check1"
EnableClientScript="true"
OnServerValidate="CustomValidator1_ServerValidate"></asp:CustomValidator></d
iv>
Code-behind:
protected void CustomValidator1_ServerValidate(object source,
ServerValidateEventArgs args)
{
args.IsValid = true;
if (TextBox1.Text == "" && TextBox2.Text == "") args.IsValid = false;
}
protected void Button1_Click(object sender, EventArgs e)
{
Response.Write(Page.IsValid);
}
If the client browser has enabled javascript, the validation will be done
on client-side; otherwise the server-side event ServerValidate will check
the two textboxes.
Sincerely,
Walter Wang (
[email protected], remove 'online.')
Microsoft Online Community Support
==================================================
Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/subscriptions/managednewsgroups/default.aspx#notif
ications. If you are using Outlook Express, please make sure you clear the
check box "Tools/Options/Read: Get 300 headers at a time" to see your reply
promptly.
Note: The MSDN Managed Newsgroup support offering is for non-urgent issues
where an initial response from the community or a Microsoft Support
Engineer within 1 business day is acceptable. Please note that each follow
up response may take approximately 2 business days as the support
professional working with you may need further investigation to reach the
most efficient resolution. The offering is not appropriate for situations
that require urgent, real-time or phone-based interactions or complex
project analysis and dump analysis issues. Issues of this nature are best
handled working with a dedicated Microsoft Support Engineer by contacting
Microsoft Customer Support Services (CSS) at
http://msdn.microsoft.com/subscriptions/support/default.aspx.
==================================================
This posting is provided "AS IS" with no warranties, and confers no rights.