473,499 Members | 1,589 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Control Tab Movement in CustomValidation Script

kpg
Hi all,

This should be simple...

I have a TextBox1 and a customvalidation 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.GetElementByID("TextBox1").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 2914
kpg

<%@ Page Language="VB" AutoEventWireup="True" %>
<HTML>
<body>
<form id="Form1" runat="server">
<h3><asp:textbox id="Text1" runat="server"></asp:textbox>&nbsp;&nbsp;
<asp:customvalidator id="CustomValidator1" runat="server"
ControlToValidate="Text1" ErrorMessage="CustomValidator"
ClientValidationFunction="MyTest"></asp:customvalidator></h3>
<p><asp:button id="Button1" runat="server" Text="Validate"></asp:button>
</form>
<script language="vbscript">
sub MyTest(source, arguments)
arguments.IsValid=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="javascript">
function MyTest(source, arguments)
{
arguments.IsValid=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 ControlToEvaluate 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. "Professional 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****@PeterBlum.com
Creator of "Professional Validation And More" at
http://www.peterblum.com/vam/home.aspx

"kpg" <ip***@thereforeiam.com> wrote in message
news:Oo**************@TK2MSFTNGP12.phx.gbl...

<%@ Page Language="VB" AutoEventWireup="True" %>
<HTML>
<body>
<form id="Form1" runat="server">
<h3><asp:textbox id="Text1" runat="server"></asp:textbox>&nbsp;&nbsp;
<asp:customvalidator id="CustomValidator1" runat="server"
ControlToValidate="Text1" ErrorMessage="CustomValidator"
ClientValidationFunction="MyTest"></asp:customvalidator></h3>
<p><asp:button id="Button1" runat="server" Text="Validate"></asp:button>
</form>
<script language="vbscript">
sub MyTest(source, arguments)
arguments.IsValid=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
1142
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,...
7
1924
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...
1
1737
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...
0
1004
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...
1
1475
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? ...
0
1553
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...
2
7869
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...
1
1291
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...
1
1379
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...
0
7132
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,...
1
6899
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...
0
5475
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,...
0
4602
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...
0
3103
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...
0
3094
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1427
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
1
665
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
302
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...

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.