Thanks Philip, nice demo! But I think the source code applies to a different
demo?
:
The custom server control that you will build has to have a strategy to
validate the entries using javascript. This is what we are doing here. In
other words, this discussion is not irrelevant. You can package the
javascript skills that you might learn from this discussion into your custom
validator's client-side script and add to it the portion that you already
developed (server-side validation).
As for the *only fault* that you identified (can't mark the missing fields
visually), I modified the code slightly to do that and placed it as a demo on
this link:
http://www.webswapp.com/codesamples/aspnet20/textbox/demo2.aspx
--
HTH,
Phillip Williams
http://www.societopia.net
http://www.webswapp.com
:
Even more clever!
The only fault I see in this is that I can't mark the missing fields
visually, right now I use validators to put exclamation point gif next to
missing fields and error text in a validation summary. so for the time being
I'm not using a validator but rejecting the page if server side method
determines all phone fields are blank and setting visible label fields with
image and error text.
Now I'm thinking it would be cool if I could perform the tests server side,
then trigger validation controls from server code, so the validation errors
would appear in the validation summary.
Sorry, guess I'm want it just so
Thanks for a classy suggestion though, I might wind up having to reduce
expectations and use it
:
You can also have each of those textboxes copying their value to a hidden
textbox by handling the client-side event named "onchange", like this:
<asp:TextBox ID="txtHomePhone" runat="server"
onchange="copyvalue();"></asp:TextBox>
<asp:TextBox ID="txtBusPhone" runat="server"
onchange="copyvalue();"></asp:TextBox>
<asp:TextBox ID="txtMobile" runat="server"
onchange="copyvalue();"></asp:TextBox>
At the end of your webform add a hidden textbox with validation controls
(for both required field and valid phone entry):
<asp:TextBox ID="txtPhone" Runat="server" CssClass="Hidden"></asp:TextBox>
<asp:RequiredFieldValidator ControlToValidate="txtPhone" Runat="server"
ErrorMessage="You must enter at least one phone
number"></asp:RequiredFieldValidator>
<asp:RegularExpressionValidator ControlToValidate ="txtPhone" Runat="server"
ErrorMessage="Not a vaild phone nubmer"
Display="Dynamic"
ValidationExpression="^\(?\d{3}\)?\s?\d{3}[-\s]?\d{4}$"></asp:RegularExpressionValidator>
Then in the javascript script section of your code:
function copyvalue()
{
var txtSrc = window.event.srcElement;
var txtTarget = document.getElementById ("txtPhone");
if (txtTarget!=null)
{
txtTarget.value=txtSrc.value;
}
}
Of course make sure your stylesheet has the .hidden style defined, e.g.
.Hidden {display:none;}
--
HTH,
Phillip Williams
http://www.societopia.net
http://www.webswapp.com
:
Clever workaround Phillip!
but I'm looking for a way to just insure that at least one of three
textboxes has a value in it without designating on as the mandatory field, as
these are in different sections of the form - e.g. work fields vs home fields.
I have a server side validation working now, but since it doesn't use
validation controls the error message doesn't disappear once the user tabs
out of the field.
I guess I'm going to have to brush up on my javascript!
Thanks for your suggestion.
:
<table>
<tr>
<td>
<asp

ropDownList ID="ddlPhoneType" runat="server">
<asp:ListItem Value="Phone">Phone</asp:ListItem>
<asp:ListItem Value="Mobile">Mobile</asp:ListItem>
<asp:ListItem Value="Fax">Fax</asp:ListItem>
</asp

ropDownList>
</td>
<td>
<asp:TextBox ID="txtMandatoryPhone"
runat="server"></asp:TextBox><font color="red">*</font>
<asp:RequiredFieldValidator ID="valMandatoryPhone"
runat="Server" ControlToValidate="txtMandatoryPhone"
ErrorMessage="You must enter at least one contact
information"></asp:RequiredFieldValidator>
</td>
</tr>
<tr>
<td>
<asp

ropDownList ID="DropDownList1" runat="server">
<asp:ListItem></asp:ListItem>
<asp:ListItem Value="Phone">Phone</asp:ListItem>
<asp:ListItem Value="Mobile">Mobile</asp:ListItem>
<asp:ListItem Value="Fax">Fax</asp:ListItem>
</asp

ropDownList>
</td>
<td>
<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
</td>
</tr>
<tr>
<td>
<asp

ropDownList ID="DropDownList2" runat="server">
<asp:ListItem></asp:ListItem>
<asp:ListItem Value="Phone">Phone</asp:ListItem>
<asp:ListItem Value="Mobile">Mobile</asp:ListItem>
<asp:ListItem Value="Fax">Fax</asp:ListItem>
</asp

ropDownList>
</td>
<td>
<asp:TextBox ID="TextBox2" runat="server"></asp:TextBox>
</td>
</tr>
</table>
--
HTH,
Phillip Williams
http://www.societopia.net
http://www.webswapp.com
:
I need to insure that at least one of three phone number fields has a value
(requiredfield) but I'm not sure of a way to implement this without server
side logic. Is there a way to use the validation controls to do this?
Thanks.