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. 12 2050
I am not sure if there is a way to do that using the validation controls
other than using the CustomValidator Control. The CustomValidator Control
does require you to write server-side validation code, but if you write a
client-side JavaScript function as well you can set the
ClientValidatio nFunction property to allow JavaScript enabled browsers to
perform the validation client-side. I have never used this property myself,
but it doesn't sound like it should be too hard. Good Luck!
--
Nathan Sokalski nj********@hotm ail.com http://www.nathansokalski.com/
"Dabbler" <Da*****@discus sions.microsoft .com> wrote in message
news:C5******** *************** ***********@mic rosoft.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.
<table>
<tr>
<td>
<asp:DropDownLi st ID="ddlPhoneTyp e" runat="server">
<asp:ListItem Value="Phone">P hone</asp:ListItem>
<asp:ListItem Value="Mobile"> Mobile</asp:ListItem>
<asp:ListItem Value="Fax">Fax </asp:ListItem>
</asp:DropDownLis t>
</td>
<td>
<asp:TextBox ID="txtMandator yPhone"
runat="server"> </asp:TextBox><fo nt color="red">*</font>
<asp:RequiredFi eldValidator ID="valMandator yPhone"
runat="Server" ControlToValida te="txtMandator yPhone"
ErrorMessage="Y ou must enter at least one contact
information"></asp:RequiredFie ldValidator>
</td>
</tr>
<tr>
<td>
<asp:DropDownLi st ID="DropDownLis t1" runat="server">
<asp:ListItem ></asp:ListItem>
<asp:ListItem Value="Phone">P hone</asp:ListItem>
<asp:ListItem Value="Mobile"> Mobile</asp:ListItem>
<asp:ListItem Value="Fax">Fax </asp:ListItem>
</asp:DropDownLis t>
</td>
<td>
<asp:TextBox ID="TextBox1" runat="server"> </asp:TextBox>
</td>
</tr>
<tr>
<td>
<asp:DropDownLi st ID="DropDownLis t2" runat="server">
<asp:ListItem ></asp:ListItem>
<asp:ListItem Value="Phone">P hone</asp:ListItem>
<asp:ListItem Value="Mobile"> Mobile</asp:ListItem>
<asp:ListItem Value="Fax">Fax </asp:ListItem>
</asp:DropDownLis t>
</td>
<td>
<asp:TextBox ID="TextBox2" runat="server"> </asp:TextBox>
</td>
</tr>
</table>
--
HTH,
Phillip Williams http://www.societopia.net http://www.webswapp.com
"Dabbler" wrote: 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.
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.
"Phillip Williams" wrote: <table> <tr> <td> <asp:DropDownLi st ID="ddlPhoneTyp e" runat="server"> <asp:ListItem Value="Phone">P hone</asp:ListItem> <asp:ListItem Value="Mobile"> Mobile</asp:ListItem> <asp:ListItem Value="Fax">Fax </asp:ListItem> </asp:DropDownLis t> </td> <td> <asp:TextBox ID="txtMandator yPhone" runat="server"> </asp:TextBox><fo nt color="red">*</font> <asp:RequiredFi eldValidator ID="valMandator yPhone" runat="Server" ControlToValida te="txtMandator yPhone" ErrorMessage="Y ou must enter at least one contact information"></asp:RequiredFie ldValidator> </td> </tr> <tr> <td> <asp:DropDownLi st ID="DropDownLis t1" runat="server"> <asp:ListItem ></asp:ListItem> <asp:ListItem Value="Phone">P hone</asp:ListItem> <asp:ListItem Value="Mobile"> Mobile</asp:ListItem> <asp:ListItem Value="Fax">Fax </asp:ListItem> </asp:DropDownLis t> </td> <td> <asp:TextBox ID="TextBox1" runat="server"> </asp:TextBox> </td> </tr> <tr> <td> <asp:DropDownLi st ID="DropDownLis t2" runat="server"> <asp:ListItem ></asp:ListItem> <asp:ListItem Value="Phone">P hone</asp:ListItem> <asp:ListItem Value="Mobile"> Mobile</asp:ListItem> <asp:ListItem Value="Fax">Fax </asp:ListItem> </asp:DropDownLis t> </td> <td> <asp:TextBox ID="TextBox2" runat="server"> </asp:TextBox> </td> </tr> </table> -- HTH, Phillip Williams http://www.societopia.net http://www.webswapp.com
"Dabbler" wrote:
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.
Thanks Nathan, I think I will try the CustomValidator , I just need to brush
up on my javascript to access the values of the other controls.
There should be an intrinsic pattern to edit one control against multiple
other controls (MultiCompareVa lidator ?).
"Nathan Sokalski" wrote: I am not sure if there is a way to do that using the validation controls other than using the CustomValidator Control. The CustomValidator Control does require you to write server-side validation code, but if you write a client-side JavaScript function as well you can set the ClientValidatio nFunction property to allow JavaScript enabled browsers to perform the validation client-side. I have never used this property myself, but it doesn't sound like it should be too hard. Good Luck! -- Nathan Sokalski nj********@hotm ail.com http://www.nathansokalski.com/
"Dabbler" <Da*****@discus sions.microsoft .com> wrote in message news:C5******** *************** ***********@mic rosoft.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.
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="txtHomePhon e" runat="server"
onchange="copyv alue();"></asp:TextBox>
<asp:TextBox ID="txtBusPhone " runat="server"
onchange="copyv alue();"></asp:TextBox>
<asp:TextBox ID="txtMobile" runat="server"
onchange="copyv alue();"></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="Hidde n"></asp:TextBox>
<asp:RequiredFi eldValidator ControlToValida te="txtPhone" Runat="server"
ErrorMessage="Y ou must enter at least one phone
number"></asp:RequiredFie ldValidator>
<asp:RegularExp ressionValidato r ControlToValida te ="txtPhone" Runat="server"
ErrorMessage="N ot a vaild phone nubmer"
Display="Dynami c"
ValidationExpre ssion="^\(?\d{3 }\)?\s?\d{3}[-\s]?\d{4}$"></asp:RegularExpr essionValidator >
Then in the javascript script section of your code:
function copyvalue()
{
var txtSrc = window.event.sr cElement;
var txtTarget = document.getEle mentById ("txtPhone") ;
if (txtTarget!=nul l)
{
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
"Dabbler" wrote: 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.
"Phillip Williams" wrote:
<table> <tr> <td> <asp:DropDownLi st ID="ddlPhoneTyp e" runat="server"> <asp:ListItem Value="Phone">P hone</asp:ListItem> <asp:ListItem Value="Mobile"> Mobile</asp:ListItem> <asp:ListItem Value="Fax">Fax </asp:ListItem> </asp:DropDownLis t> </td> <td> <asp:TextBox ID="txtMandator yPhone" runat="server"> </asp:TextBox><fo nt color="red">*</font> <asp:RequiredFi eldValidator ID="valMandator yPhone" runat="Server" ControlToValida te="txtMandator yPhone" ErrorMessage="Y ou must enter at least one contact information"></asp:RequiredFie ldValidator> </td> </tr> <tr> <td> <asp:DropDownLi st ID="DropDownLis t1" runat="server"> <asp:ListItem ></asp:ListItem> <asp:ListItem Value="Phone">P hone</asp:ListItem> <asp:ListItem Value="Mobile"> Mobile</asp:ListItem> <asp:ListItem Value="Fax">Fax </asp:ListItem> </asp:DropDownLis t> </td> <td> <asp:TextBox ID="TextBox1" runat="server"> </asp:TextBox> </td> </tr> <tr> <td> <asp:DropDownLi st ID="DropDownLis t2" runat="server"> <asp:ListItem ></asp:ListItem> <asp:ListItem Value="Phone">P hone</asp:ListItem> <asp:ListItem Value="Mobile"> Mobile</asp:ListItem> <asp:ListItem Value="Fax">Fax </asp:ListItem> </asp:DropDownLis t> </td> <td> <asp:TextBox ID="TextBox2" runat="server"> </asp:TextBox> </td> </tr> </table> -- HTH, Phillip Williams http://www.societopia.net http://www.webswapp.com
"Dabbler" wrote:
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.
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 ;)
"Phillip Williams" wrote: 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="txtHomePhon e" runat="server" onchange="copyv alue();"></asp:TextBox> <asp:TextBox ID="txtBusPhone " runat="server" onchange="copyv alue();"></asp:TextBox> <asp:TextBox ID="txtMobile" runat="server" onchange="copyv alue();"></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="Hidde n"></asp:TextBox> <asp:RequiredFi eldValidator ControlToValida te="txtPhone" Runat="server" ErrorMessage="Y ou must enter at least one phone number"></asp:RequiredFie ldValidator> <asp:RegularExp ressionValidato r ControlToValida te ="txtPhone" Runat="server" ErrorMessage="N ot a vaild phone nubmer" Display="Dynami c" ValidationExpre ssion="^\(?\d{3 }\)?\s?\d{3}[-\s]?\d{4}$"></asp:RegularExpr essionValidator >
Then in the javascript script section of your code: function copyvalue() { var txtSrc = window.event.sr cElement; var txtTarget = document.getEle mentById ("txtPhone") ; if (txtTarget!=nul l) { 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
"Dabbler" wrote:
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.
"Phillip Williams" wrote:
<table> <tr> <td> <asp:DropDownLi st ID="ddlPhoneTyp e" runat="server"> <asp:ListItem Value="Phone">P hone</asp:ListItem> <asp:ListItem Value="Mobile"> Mobile</asp:ListItem> <asp:ListItem Value="Fax">Fax </asp:ListItem> </asp:DropDownLis t> </td> <td> <asp:TextBox ID="txtMandator yPhone" runat="server"> </asp:TextBox><fo nt color="red">*</font> <asp:RequiredFi eldValidator ID="valMandator yPhone" runat="Server" ControlToValida te="txtMandator yPhone" ErrorMessage="Y ou must enter at least one contact information"></asp:RequiredFie ldValidator> </td> </tr> <tr> <td> <asp:DropDownLi st ID="DropDownLis t1" runat="server"> <asp:ListItem ></asp:ListItem> <asp:ListItem Value="Phone">P hone</asp:ListItem> <asp:ListItem Value="Mobile"> Mobile</asp:ListItem> <asp:ListItem Value="Fax">Fax </asp:ListItem> </asp:DropDownLis t> </td> <td> <asp:TextBox ID="TextBox1" runat="server"> </asp:TextBox> </td> </tr> <tr> <td> <asp:DropDownLi st ID="DropDownLis t2" runat="server"> <asp:ListItem ></asp:ListItem> <asp:ListItem Value="Phone">P hone</asp:ListItem> <asp:ListItem Value="Mobile"> Mobile</asp:ListItem> <asp:ListItem Value="Fax">Fax </asp:ListItem> </asp:DropDownLis t> </td> <td> <asp:TextBox ID="TextBox2" runat="server"> </asp:TextBox> </td> </tr> </table> -- HTH, Phillip Williams http://www.societopia.net http://www.webswapp.com
"Dabbler" wrote:
> 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. > >
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/...box/demo2.aspx
--
HTH,
Phillip Williams http://www.societopia.net http://www.webswapp.com
"Dabbler" wrote: 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 ;)
"Phillip Williams" wrote:
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="txtHomePhon e" runat="server" onchange="copyv alue();"></asp:TextBox> <asp:TextBox ID="txtBusPhone " runat="server" onchange="copyv alue();"></asp:TextBox> <asp:TextBox ID="txtMobile" runat="server" onchange="copyv alue();"></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="Hidde n"></asp:TextBox> <asp:RequiredFi eldValidator ControlToValida te="txtPhone" Runat="server" ErrorMessage="Y ou must enter at least one phone number"></asp:RequiredFie ldValidator> <asp:RegularExp ressionValidato r ControlToValida te ="txtPhone" Runat="server" ErrorMessage="N ot a vaild phone nubmer" Display="Dynami c" ValidationExpre ssion="^\(?\d{3 }\)?\s?\d{3}[-\s]?\d{4}$"></asp:RegularExpr essionValidator >
Then in the javascript script section of your code: function copyvalue() { var txtSrc = window.event.sr cElement; var txtTarget = document.getEle mentById ("txtPhone") ; if (txtTarget!=nul l) { 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
"Dabbler" wrote:
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.
"Phillip Williams" wrote:
> <table> > <tr> > <td> > <asp:DropDownLi st ID="ddlPhoneTyp e" runat="server"> > <asp:ListItem Value="Phone">P hone</asp:ListItem> > <asp:ListItem Value="Mobile"> Mobile</asp:ListItem> > <asp:ListItem Value="Fax">Fax </asp:ListItem> > </asp:DropDownLis t> > </td> > <td> > <asp:TextBox ID="txtMandator yPhone" > runat="server"> </asp:TextBox><fo nt color="red">*</font> > <asp:RequiredFi eldValidator ID="valMandator yPhone" > runat="Server" ControlToValida te="txtMandator yPhone" > ErrorMessage="Y ou must enter at least one contact > information"></asp:RequiredFie ldValidator> > </td> > </tr> > <tr> > <td> > <asp:DropDownLi st ID="DropDownLis t1" runat="server"> > <asp:ListItem ></asp:ListItem> > <asp:ListItem Value="Phone">P hone</asp:ListItem> > <asp:ListItem Value="Mobile"> Mobile</asp:ListItem> > <asp:ListItem Value="Fax">Fax </asp:ListItem> > </asp:DropDownLis t> > </td> > <td> > <asp:TextBox ID="TextBox1" runat="server"> </asp:TextBox> > </td> > </tr> > <tr> > <td> > <asp:DropDownLi st ID="DropDownLis t2" runat="server"> > <asp:ListItem ></asp:ListItem> > <asp:ListItem Value="Phone">P hone</asp:ListItem> > <asp:ListItem Value="Mobile"> Mobile</asp:ListItem> > <asp:ListItem Value="Fax">Fax </asp:ListItem> > </asp:DropDownLis t> > </td> > <td> > <asp:TextBox ID="TextBox2" runat="server"> </asp:TextBox> > </td> > </tr> > </table> > -- > HTH, > Phillip Williams > http://www.societopia.net > http://www.webswapp.com > > > "Dabbler" wrote: > > > 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. > > > >
Thanks Philip, nice demo! But I think the source code applies to a different
demo?
"Phillip Williams" wrote: 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/...box/demo2.aspx
-- HTH, Phillip Williams http://www.societopia.net http://www.webswapp.com
"Dabbler" wrote:
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 ;)
"Phillip Williams" wrote:
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="txtHomePhon e" runat="server" onchange="copyv alue();"></asp:TextBox> <asp:TextBox ID="txtBusPhone " runat="server" onchange="copyv alue();"></asp:TextBox> <asp:TextBox ID="txtMobile" runat="server" onchange="copyv alue();"></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="Hidde n"></asp:TextBox> <asp:RequiredFi eldValidator ControlToValida te="txtPhone" Runat="server" ErrorMessage="Y ou must enter at least one phone number"></asp:RequiredFie ldValidator> <asp:RegularExp ressionValidato r ControlToValida te ="txtPhone" Runat="server" ErrorMessage="N ot a vaild phone nubmer" Display="Dynami c" ValidationExpre ssion="^\(?\d{3 }\)?\s?\d{3}[-\s]?\d{4}$"></asp:RegularExpr essionValidator >
Then in the javascript script section of your code: function copyvalue() { var txtSrc = window.event.sr cElement; var txtTarget = document.getEle mentById ("txtPhone") ; if (txtTarget!=nul l) { 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
"Dabbler" wrote:
> 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. > > "Phillip Williams" wrote: > > > <table> > > <tr> > > <td> > > <asp:DropDownLi st ID="ddlPhoneTyp e" runat="server"> > > <asp:ListItem Value="Phone">P hone</asp:ListItem> > > <asp:ListItem Value="Mobile"> Mobile</asp:ListItem> > > <asp:ListItem Value="Fax">Fax </asp:ListItem> > > </asp:DropDownLis t> > > </td> > > <td> > > <asp:TextBox ID="txtMandator yPhone" > > runat="server"> </asp:TextBox><fo nt color="red">*</font> > > <asp:RequiredFi eldValidator ID="valMandator yPhone" > > runat="Server" ControlToValida te="txtMandator yPhone" > > ErrorMessage="Y ou must enter at least one contact > > information"></asp:RequiredFie ldValidator> > > </td> > > </tr> > > <tr> > > <td> > > <asp:DropDownLi st ID="DropDownLis t1" runat="server"> > > <asp:ListItem ></asp:ListItem> > > <asp:ListItem Value="Phone">P hone</asp:ListItem> > > <asp:ListItem Value="Mobile"> Mobile</asp:ListItem> > > <asp:ListItem Value="Fax">Fax </asp:ListItem> > > </asp:DropDownLis t> > > </td> > > <td> > > <asp:TextBox ID="TextBox1" runat="server"> </asp:TextBox> > > </td> > > </tr> > > <tr> > > <td> > > <asp:DropDownLi st ID="DropDownLis t2" runat="server"> > > <asp:ListItem ></asp:ListItem> > > <asp:ListItem Value="Phone">P hone</asp:ListItem> > > <asp:ListItem Value="Mobile"> Mobile</asp:ListItem> > > <asp:ListItem Value="Fax">Fax </asp:ListItem> > > </asp:DropDownLis t> > > </td> > > <td> > > <asp:TextBox ID="TextBox2" runat="server"> </asp:TextBox> > > </td> > > </tr> > > </table> > > -- > > HTH, > > Phillip Williams > > http://www.societopia.net > > http://www.webswapp.com > > > > > > "Dabbler" wrote: > > > > > 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. > > > > > >
Are you sure you clicked on the right tab for the source code? There are 2
demos on the same section. The source code can be reached directly through
this link: http://www.webswapp.com/codesamples/...box/demo2.aspx
--
HTH,
Phillip Williams http://www.societopia.net http://www.webswapp.com
"Dabbler" wrote: Thanks Philip, nice demo! But I think the source code applies to a different demo?
"Phillip Williams" wrote:
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/...box/demo2.aspx
-- HTH, Phillip Williams http://www.societopia.net http://www.webswapp.com
"Dabbler" wrote:
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 ;)
"Phillip Williams" wrote:
> 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="txtHomePhon e" runat="server" > onchange="copyv alue();"></asp:TextBox> > <asp:TextBox ID="txtBusPhone " runat="server" > onchange="copyv alue();"></asp:TextBox> > <asp:TextBox ID="txtMobile" runat="server" > onchange="copyv alue();"></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="Hidde n"></asp:TextBox> > <asp:RequiredFi eldValidator ControlToValida te="txtPhone" Runat="server" > ErrorMessage="Y ou must enter at least one phone > number"></asp:RequiredFie ldValidator> > <asp:RegularExp ressionValidato r ControlToValida te ="txtPhone" Runat="server" > ErrorMessage="N ot a vaild phone nubmer" > Display="Dynami c" > ValidationExpre ssion="^\(?\d{3 }\)?\s?\d{3}[-\s]?\d{4}$"></asp:RegularExpr essionValidator > > > Then in the javascript script section of your code: > function copyvalue() > { > var txtSrc = window.event.sr cElement; > var txtTarget = document.getEle mentById ("txtPhone") ; > if (txtTarget!=nul l) > { > 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 > > > "Dabbler" wrote: > > > 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. > > > > "Phillip Williams" wrote: > > > > > <table> > > > <tr> > > > <td> > > > <asp:DropDownLi st ID="ddlPhoneTyp e" runat="server"> > > > <asp:ListItem Value="Phone">P hone</asp:ListItem> > > > <asp:ListItem Value="Mobile"> Mobile</asp:ListItem> > > > <asp:ListItem Value="Fax">Fax </asp:ListItem> > > > </asp:DropDownLis t> > > > </td> > > > <td> > > > <asp:TextBox ID="txtMandator yPhone" > > > runat="server"> </asp:TextBox><fo nt color="red">*</font> > > > <asp:RequiredFi eldValidator ID="valMandator yPhone" > > > runat="Server" ControlToValida te="txtMandator yPhone" > > > ErrorMessage="Y ou must enter at least one contact > > > information"></asp:RequiredFie ldValidator> > > > </td> > > > </tr> > > > <tr> > > > <td> > > > <asp:DropDownLi st ID="DropDownLis t1" runat="server"> > > > <asp:ListItem ></asp:ListItem> > > > <asp:ListItem Value="Phone">P hone</asp:ListItem> > > > <asp:ListItem Value="Mobile"> Mobile</asp:ListItem> > > > <asp:ListItem Value="Fax">Fax </asp:ListItem> > > > </asp:DropDownLis t> > > > </td> > > > <td> > > > <asp:TextBox ID="TextBox1" runat="server"> </asp:TextBox> > > > </td> > > > </tr> > > > <tr> > > > <td> > > > <asp:DropDownLi st ID="DropDownLis t2" runat="server"> > > > <asp:ListItem ></asp:ListItem> > > > <asp:ListItem Value="Phone">P hone</asp:ListItem> > > > <asp:ListItem Value="Mobile"> Mobile</asp:ListItem> > > > <asp:ListItem Value="Fax">Fax </asp:ListItem> > > > </asp:DropDownLis t> > > > </td> > > > <td> > > > <asp:TextBox ID="TextBox2" runat="server"> </asp:TextBox> > > > </td> > > > </tr> > > > </table> > > > -- > > > HTH, > > > Phillip Williams > > > http://www.societopia.net > > > http://www.webswapp.com > > > > > > > > > "Dabbler" wrote: > > > > > > > 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. > > > > > > > >
This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: Eric Linders |
last post by:
Hi,
I'm trying to figure out the most efficient method for taking the
first character in a string (which will be a number), and use
it as a variable to check to see if the other numbers in the string
match that first number. I'm using this code for form validation of a
telephone number.
Previous records from the past few months show that when someone is
just messing around on one of our forms (to waste our time), they type
|
by: Claudio Jolowicz |
last post by:
I am trying to find a solution to the following design problem
(code at the bottom):
We are implementing a trader agent that can trade with other traders
on an electronical trading platform. To make the trader more
extensible, we have defined a strategy interface and implemented this
interface for different trading strategies. The problem relates to how
to connect the trader and the strategy.
The problem is tricky because the strategy...
|
by: Kathy |
last post by:
I have a form to generate a report.
On the form are several textboxes and a "Generate" button.
I would like to have the button grayed (not enabled), unless the data in
each of the dependant textboxes is valid.
What is the proper procedure for doing this?
It seems the Validating and Validated events for each control only fire when
it loses focus.
I would like the button to be enabled as soon as the data is valid (before
leaving the...
|
by: honcho |
last post by:
My ASP.NET web application has a flaw that produces false security-violation
alarms.
There are several categories of users for this web site, e.g. Colonels,
Sergeants, Private_1s,
and Private_2s. Colonels may visit any page in the web site. Sergeants may
visit only non-com
pages. The non-com pages consist of non-com-0, non-com-1, and non-com-2
pages. Private_1s may visit non-com-0 and non-com-1 pages. Private_2s may
visit...
|
by: Mr Newbie |
last post by:
I am using a DataGrid for Edit and Update. However, Im wondering what the
best strategy for client side validation would be as I dont think the
validators can reference the TextBoxes which come up in the Table Rendered
by the DataGrid when Editing/Updating or maybe I'm wrong ?????
I know I can validate inside the update event, but i wondered if anyone has
tried to do this client side ?
Cheers - Mr Newbie.
| |
by: daniel.boorn |
last post by:
Form validation using JavaScript has never been as easy and simple! We
have developed a free generic form validation script that can validate
any form with very little JavaScript required in form!
For example:
A normal HTML form with out validation:
<form action="foobar.htm" method="get">
<div>Name: <input type="text" name="customerName" value=""></div>
|
by: Lucky Star |
last post by:
Hello All,
We have the following requirement.
Please send matching profiles along with the rate Expectations,
Availability and Contact Details for the same.
Position: Lead Validation Consultant
|
by: hgeithus |
last post by:
Hi. I'm doing a form at my website, and I found this document which is very interesting: Javascript form validation - doing it right .
I have a little question though. All the documents within my page has the *.php extention since I'm using PHP the most. I'm also using gettext to translate strings to other languages. If I want to translate the string "hello", I would write it like this in my *.php document:
<?php echo _("hello");?>
In...
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look !
Part I. Meaning of...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth.
The Art of Business Website Design
Your website is...
| |
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own....
Now, this would greatly impact the work of software developers. The idea...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules.
He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms.
Adolph will...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one.
At the time of converting from word file to html my equations which are in the word document file was convert into image.
Globals.ThisAddIn.Application.ActiveDocument.Select();...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols.
I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
| |