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.
Mar 7 '06
12 2056
right you are, I clicked the C# tab by instinct, as I lost interest in VB way
before it became a typed language.
I found your findcontrol function interesting, why do you use that as
opposed to document.getEle mentById? is it because you might give the same id
to two element types?
Thanks again.
"Phillip Williams" wrote: 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. > > > > > > > > > >
The page you were looking at in this demo is a content page; which means that
any controls on it will have their browser ID prefixed with the
NamingContainer (s) IDs. For example the textbox for entering the date has an
ID that looks like this: ctl00_ContentPl aceHolder1_txtD ate1. If I had simply
used document.getEle mentById("txtDa te1") I would have not found it. So my
customized FindControl JavaScript function searches for a control with an ID
that ends with the ID I am looking for.
--
HTH,
Phillip Williams http://www.societopia.net http://www.webswapp.com
"Dabbler" wrote: right you are, I clicked the C# tab by instinct, as I lost interest in VB way before it became a typed language.
I found your findcontrol function interesting, why do you use that as opposed to document.getEle mentById? is it because you might give the same id to two element types?
Thanks again.
"Phillip Williams" wrote:
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. > > > > > > > > > > > >
So much to learn, so little time!
Thanks Phillip.
"Phillip Williams" wrote: The page you were looking at in this demo is a content page; which means that any controls on it will have their browser ID prefixed with the NamingContainer (s) IDs. For example the textbox for entering the date has an ID that looks like this: ctl00_ContentPl aceHolder1_txtD ate1. If I had simply used document.getEle mentById("txtDa te1") I would have not found it. So my customized FindControl JavaScript function searches for a control with an ID that ends with the ID I am looking for.
-- HTH, Phillip Williams http://www.societopia.net http://www.webswapp.com
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: 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: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
|
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: 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?
|
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
|
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...
| |