473,626 Members | 3,388 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Control Tab Movement in CustomValidatio n Script

kpg
Hi all,

This should be simple...

I have a TextBox1 and a customvalidatio n control linked to it.
I use a client side script to validate the textbox.
If the data is not valid I want to return focus to the textbox.
I tried document.GetEle mentByID("TextB ox1").focus(); and
doucment.Form1. TextBox1.focus( ); to no avail.

How can I return focus to the TextBox1 after the uses hits
<TAB> to move and the client side script detects an error?

Thanks.
kpg

Nov 19 '05 #1
2 2931
kpg

<%@ Page Language="VB" AutoEventWireup ="True" %>
<HTML>
<body>
<form id="Form1" runat="server">
<h3><asp:textbo x id="Text1" runat="server"> </asp:textbox>&nb sp;&nbsp;
<asp:customvali dator id="CustomValid ator1" runat="server"
ControlToValida te="Text1" ErrorMessage="C ustomValidator"
ClientValidatio nFunction="MyTe st"></asp:customvalid ator></h3>
<p><asp:butto n id="Button1" runat="server" Text="Validate" ></asp:button>
</form>
<script language="vbscr ipt">
sub MyTest(source, arguments)
arguments.IsVal id=false
document.Form1. Text1.focus
End Sub
</script>
</P>
</body>
</HTML>

Nov 19 '05 #2
A few comments:

1. I strongly recommend using Javascript over VBScript. VBScript is
supported on IE and IE/Mac. Other browsers may generate errors when they hit
your script. The code is very easy to convert:
<script language="javas cript">
function MyTest(source, arguments)
{
arguments.IsVal id=false;
document.Form1. Text1.focus();
}
</script>

2. Be sure to treat everything case sensitively. You wrote "GetElementByID "
when the name is "getElementById ()"

3. Be sure that functions have () after them. You wrote focus, not focus().

4. While the idea is pretty good, this custom validator will be fired when
the user edits ControlToEvalua te and on submit. If you use this technique is
several validators, when you click submit, they will all attempt to set
focus and the last one with the error will win.

5. "Profession al Validation And More"
(http://www.peterblum.com/vam/home.aspx) is a replacement to Microsoft's
validators that overcomes its numerous limitations so you can avoid custom
coding and hacks. It includes 22 validators that support more browsers than
Microsofts on the client-side.
It has several features designed to draw the user's attention to the field
with the error:
- set focus to the field with separate options for onchange events and on
submit
- change the style of the field
- change the style of the field's label or other nearby element
- show an alert
- blink the error message

--- Peter Blum
www.PeterBlum.com
Email: PL****@PeterBlu m.com
Creator of "Profession al Validation And More" at
http://www.peterblum.com/vam/home.aspx

"kpg" <ip***@therefor eiam.com> wrote in message
news:Oo******** ******@TK2MSFTN GP12.phx.gbl...

<%@ Page Language="VB" AutoEventWireup ="True" %>
<HTML>
<body>
<form id="Form1" runat="server">
<h3><asp:textbo x id="Text1" runat="server"> </asp:textbox>&nb sp;&nbsp;
<asp:customvali dator id="CustomValid ator1" runat="server"
ControlToValida te="Text1" ErrorMessage="C ustomValidator"
ClientValidatio nFunction="MyTe st"></asp:customvalid ator></h3>
<p><asp:butto n id="Button1" runat="server" Text="Validate" ></asp:button>
</form>
<script language="vbscr ipt">
sub MyTest(source, arguments)
arguments.IsVal id=false
document.Form1. Text1.focus
End Sub
</script>
</P>
</body>
</HTML>

Nov 19 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
1150
by: sdbranum | last post by:
I have been using Visual C#.NET to code a large project having many data adapters, data sets, datagrids, multiple forms with tab pages, each containing various controls (mostly label, text boxes, check boxes, date pickers, combo boxes and datagrids). I have been coding alone on this project for about a year, and I have experienced many problems which have not been addressed by various SP's, including the recent SP1 to Framework.NET 1.1,...
7
1933
by: |{evin | last post by:
I'm currently working on what has turned in to something much larger that I wanted it to be. The upside is that I'm getting $$ to do it... but anywho. I currently have textboxes set up to capture phone numbers, I've also got regular expression validation in place to force the format of the number to be (xxx) xxx-xxxx. The problem is, the people that are paying me don't want this. What they'd like to see is a magic textbox that fills in...
1
1745
by: philipl | last post by:
hi, i have a datagrid which display custom controls when user clicks edit, changing data. I am using customvalidator to validate this control. I can get validation of user input to work no problem when user clicks on update in datagrid. My problem is that when I try to get customvalidation to work when user changes the value in the control, as i want this to be checked as soon as user changes the control. The custom control offers an
0
1014
by: Haim | last post by:
Hello All, I am using the Microsoft tab strip control (with multi page) in my ASP .NET application. When I am moving from one tab to another I need to check the current page before I am moving to the next one, and to prevent the movement if the current page is not valid. From the main page that contains the tab control I want to invoke function
1
1486
by: SAI | last post by:
Should I bind one of the controls to the CustomValidation Object? e.g. bind text box to it. In some cases, I may need to check 2 web object contents. How to do it in one CustomValidation Object? I tried to bind a text box to CustomValidation Object and set the Client Validation to TRUE. Then I write a javascript to validate. It is no any action about the checking. Any suggestion? thanks.
0
1565
by: Chubby Arse | last post by:
Hi all, I have a control, that basically is my own version of the datagrid, except that is renderers purely readonly tabular information. When the control is rendered to the designer, I can click on the control as rendered and move it, however I cannot resize it. I can change the height and Width properties in the PropertyGrid and they change, but the control doesn't resize.
2
7882
by: hzgt9b | last post by:
Using VS2003, VB.NET, BACKGROUND I have a window forms based application that will be distributed and executed directly from CD media. The app contains a TreeView control and a WebBroswer (AxSHDocVw.AxWebBrowse) control. The TreeView is populated with nodes that when clicked play an audio clip that is stored on the CD and navigate the browser control to a specified web URL (also stored on the CD). All the web URLs are html documents...
1
1304
by: =?Utf-8?B?Ym9iYnk=?= | last post by:
I have a drop down list in my asp page. when I selectg an irem and click on a button it appears in the Grid view. But when I again come to the same page and click on the same item from Drop down list it and click on button it again add the same item onin the Grid view. So I need some validatiobn that if this item appears in Grid view Don't add in the Grid view. I can use customValidation contro. But I don't know how to use it.
1
1387
by: Craig Buchanan | last post by:
I have a Web User Control (.ascx file) that I need to valid using a CustomValidation control. Moreover, I would like use client and server validation, if possible. I have the logic for the server-side validation working correctly. I also have the have the client-side validation working once the control is embedded in a page. I would like to move the validation from the aspx page to the ascx page, but I'm concerned that the...
0
8268
marktang
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...
0
8202
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,...
0
8707
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8510
tracyyun
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...
0
7199
agi2029
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...
0
4093
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...
0
4202
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
1812
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
2
1512
bsmnconsultancy
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...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.