473,418 Members | 2,083 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,418 software developers and data experts.

A question about validate

There are three webcontrol on my asp.net form: a TextBox, a submit button
and a RegularExpressionValidator. And I had set ControlToValidate property
of the RegularExpressionValidator to the TextBox. But now, when I input a
string in the textbox and press Enter key, the form was submit without
client javascript validate.

Why? And what should I do to enable client validate before submit the form
whethe press Enter key or click Submit button?

Thanks!
Nov 19 '05 #1
11 2100
"wolf" <a@b.c> wrote in message
news:O0**************@TK2MSFTNGP11.phx.gbl...
There are three webcontrol on my asp.net form: a TextBox, a submit button
and a RegularExpressionValidator. And I had set ControlToValidate property
of the RegularExpressionValidator to the TextBox. But now, when I input a
string in the textbox and press Enter key, the form was submit without
client javascript validate.

Why? And what should I do to enable client validate before submit the form
whethe press Enter key or click Submit button?


When you say a Submit button, do you mean <input type="submit"> ? If so, how
would ASP.NET know when that button is clicked so that it can do the
client-side validation?

Try using an <asp:Button> and see if that fixes the problem.

John Saunders
Nov 19 '05 #2
> When you say a Submit button, do you mean <input type="submit"> ? If so,
how
would ASP.NET know when that button is clicked so that it can do the
client-side validation?

Try using an <asp:Button> and see if that fixes the problem.

John Saunders


No, all of the control are server side web control, and the following is my
code in WebPage1.aspx:
<%@ Page language="c#" Codebehind="WebForm1.aspx.cs"
AutoEventWireup="false" Inherits="web1.WebForm1" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" >
<HTML>
<HEAD>
<title>WebForm1</title>
<meta name="GENERATOR" Content="Microsoft Visual Studio .NET 7.1">
<meta name="CODE_LANGUAGE" Content="C#">
<meta name="vs_defaultClientScript" content="JavaScript">
<meta name="vs_targetSchema"
content="http://schemas.microsoft.com/intellisense/ie5">
</HEAD>
<body MS_POSITIONING="GridLayout">
<form id="Form1" method="post" runat="server">
<FONT face="ËÎÌå">
<asp:TextBox id="TextBox1" style="Z-INDEX: 101; LEFT: 48px; POSITION:
absolute; TOP: 56px" runat="server"></asp:TextBox>
<asp:RegularExpressionValidator id="RegularExpressionValidator1"
style="Z-INDEX: 103; LEFT: 216px; POSITION: absolute; TOP: 56px"
runat="server" ErrorMessage="RegularExpressionValidator"
ControlToValidate="TextBox1"
ValidationExpression="\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*"></asp:Reg
ularExpressionValidator>
<asp:Button id="Button1" style="Z-INDEX: 102; LEFT: 144px; POSITION:
absolute; TOP: 96px" runat="server"
Text="Button"></asp:Button></FONT>
</form>
</body>
</HTML>

Nov 19 '05 #3
My goal is that the data should be valid if they are submitted to the server
side. But the data will be submitted before validate if I press Enter key
instead of submit button.
Nov 19 '05 #4
wolf wrote:
There are three webcontrol on my asp.net form: a TextBox, a submit
button and a RegularExpressionValidator. And I had set
ControlToValidate property of the RegularExpressionValidator to the
TextBox. But now, when I input a string in the textbox and press
Enter key, the form was submit without client javascript validate.

Why? And what should I do to enable client validate before submit the
form whethe press Enter key or click Submit button?

Thanks!


I remember something about if a form contains exactly one textbox,
the enter-key will submit the form. This will submit as if a <input type=submit>
was clicked, so any client-side validators will be bypassed.
I do not know if there are ways around it (other that adding a second textbox).

The server-side version of those same validators should still work so
you might want to test for "IsPostback" and "Page.IsValid" to block
unwanted actions.

Hans Kesting
Nov 19 '05 #5
Hi,

I think you should set the CausesValidation property of the submit button
to true.

Regards,
Prakash.C

"wolf" wrote:
There are three webcontrol on my asp.net form: a TextBox, a submit button
and a RegularExpressionValidator. And I had set ControlToValidate property
of the RegularExpressionValidator to the TextBox. But now, when I input a
string in the textbox and press Enter key, the form was submit without
client javascript validate.

Why? And what should I do to enable client validate before submit the form
whethe press Enter key or click Submit button?

Thanks!

Nov 19 '05 #6
Hi,

I think you should set the CausesValidation property of the Submit Button
to true.

Prakash.C

"wolf" wrote:
There are three webcontrol on my asp.net form: a TextBox, a submit button
and a RegularExpressionValidator. And I had set ControlToValidate property
of the RegularExpressionValidator to the TextBox. But now, when I input a
string in the textbox and press Enter key, the form was submit without
client javascript validate.

Why? And what should I do to enable client validate before submit the form
whethe press Enter key or click Submit button?

Thanks!

Nov 19 '05 #7
Hi,

I think you should set the "CausesValidation" property of the submit
button to true.

Prakash.C

"Hans Kesting" wrote:
wolf wrote:
There are three webcontrol on my asp.net form: a TextBox, a submit
button and a RegularExpressionValidator. And I had set
ControlToValidate property of the RegularExpressionValidator to the
TextBox. But now, when I input a string in the textbox and press
Enter key, the form was submit without client javascript validate.

Why? And what should I do to enable client validate before submit the
form whethe press Enter key or click Submit button?

Thanks!


I remember something about if a form contains exactly one textbox,
the enter-key will submit the form. This will submit as if a <input type=submit>
was clicked, so any client-side validators will be bypassed.
I do not know if there are ways around it (other that adding a second textbox).

The server-side version of those same validators should still work so
you might want to test for "IsPostback" and "Page.IsValid" to block
unwanted actions.

Hans Kesting

Nov 19 '05 #8
Hi,

I think you should set the "CausesValidation" property of the Submit
Button to true.

Prakash.C

"Hans Kesting" wrote:
wolf wrote:
There are three webcontrol on my asp.net form: a TextBox, a submit
button and a RegularExpressionValidator. And I had set
ControlToValidate property of the RegularExpressionValidator to the
TextBox. But now, when I input a string in the textbox and press
Enter key, the form was submit without client javascript validate.

Why? And what should I do to enable client validate before submit the
form whethe press Enter key or click Submit button?

Thanks!


I remember something about if a form contains exactly one textbox,
the enter-key will submit the form. This will submit as if a <input type=submit>
was clicked, so any client-side validators will be bypassed.
I do not know if there are ways around it (other that adding a second textbox).

The server-side version of those same validators should still work so
you might want to test for "IsPostback" and "Page.IsValid" to block
unwanted actions.

Hans Kesting

Nov 19 '05 #9
No , it will submit again, and the default value of CausesValidation is
true.

"Prakash.NET" <Pr********@discussions.microsoft.com> дÈëÏûÏ¢
news:15**********************************@microsof t.com...
Hi,

I think you should set the CausesValidation property of the submit button to true.

Nov 19 '05 #10
"Hans Kesting" <ne***********@spamgourmet.com> wrote in message
news:%2****************@TK2MSFTNGP12.phx.gbl...
wolf wrote:
There are three webcontrol on my asp.net form: a TextBox, a submit
button and a RegularExpressionValidator. And I had set
ControlToValidate property of the RegularExpressionValidator to the
TextBox. But now, when I input a string in the textbox and press
Enter key, the form was submit without client javascript validate.

Why? And what should I do to enable client validate before submit the
form whethe press Enter key or click Submit button?

Thanks!


I remember something about if a form contains exactly one textbox,
the enter-key will submit the form. This will submit as if a <input
type=submit>
was clicked, so any client-side validators will be bypassed.
I do not know if there are ways around it (other that adding a second
textbox).


I vaguely remember this. If my memory is correct, you should try adding
another TextBox control. If that solves the problem, try setting the style
on the dummy textbox to "display: none" so that it does not appear. Setting
Visible to false will cause the textbox to not be rendered to the html, so
that wouldn't work.

John Saunders
Nov 19 '05 #11
Sorry for jumping in so late but the problem is quite different from what
everyone is discussing.

Internet Explorer has a strange quirk. When there is only one data entry
control on the form and you hit ENTER, it submits the page without clicking
the submit button. That means, it does not fire any javascript associated
with the button's onclick event. The submit button uses the onclick event to
fire the client-side validation. So that is skipped. In addition, it calls
the __doPostBack() function which prepares some hidden fields for the server
side to know which button was clicked. Since they have not been prepared,
the server side doesn't know to run your button's Click event. Internally,
the button's Click event runs Page.Validate(). Then it calls your method
where you test Page.IsValid is true then save. So none of this is happening.

There are two solutions:
1. Add another data entry control to your page.

2. Add this line to your page_load() method to prepare the hidden fields for
postback so at least server side validation will occur:
Page.RegisterHiddenField("__EVENTTARGET", button.ClientID)
where button is the submit button control.
--- Peter Blum
www.PeterBlum.com
Email: PL****@PeterBlum.com
Creator of "Professional Validation And More" at
http://www.peterblum.com/vam/home.aspx

"wolf" <a@b.c> wrote in message
news:O0**************@TK2MSFTNGP11.phx.gbl...
There are three webcontrol on my asp.net form: a TextBox, a submit button
and a RegularExpressionValidator. And I had set ControlToValidate property
of the RegularExpressionValidator to the TextBox. But now, when I input a
string in the textbox and press Enter key, the form was submit without
client javascript validate.

Why? And what should I do to enable client validate before submit the form
whethe press Enter key or click Submit button?

Thanks!

Nov 19 '05 #12

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

Similar topics

1
by: Nicky | last post by:
I am new on asp.net programming. Here I got a problem about validator I want to write a login.aspx page, for example, there is UserName box. I need to validate two things on UserName box, 1. It...
21
by: nephish | last post by:
i have an interesting project at work going on. here is the challenge. i am using the serial module to read data from a serial input. it comes in as a hex. i need to make it a binary and compare it...
4
by: Wayne Wengert | last post by:
I have an XML document and a corresponding xsd document I built. I want to validate the xml document against that Schema but when I use the MSDN validator it has no place to select the xsd...
0
by: SHC | last post by:
Hi all, I have a VC++ .NET 2003 - Windows XP Pro PC. I created a Win32 console application in my VC++ .NET 2003 and copied validateDOM.cpp, books.xml and books.xsd (see the attached files below)...
11
by: jjbutera | last post by:
I know how to use the ErrorProvider in my winforms..or do I? I validate the values and set the ErrorProvider in the validating event. If not valid, I set e.Cancel = True. I clear the ErrorProvider...
0
by: Marc Scheuner | last post by:
Folks, I'm faced with a dilemma here - I have an XML document and for part of it, I have an XSD schema to validate it - but not for the rest of it. Can I still validate at least part of the...
4
by: Brybot | last post by:
I have a form that i've split up into multiple asp:panels, each panel has a number of validators which work correctly. At on the last panel, i want to commit the data collected to a database. I...
24
by: Mike Hofer | last post by:
Please forgive the cross-post to multiple forums. I did it intentionally, but I *think* it was appropriate given the nature of my question. I'm working on an open source code library to help...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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,...
0
jinu1996
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...
0
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...
0
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...

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.