Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > Validate form on submit event

Reply
Thread Tools

Validate form on submit event

 
 
sergio.leon.leon@gmail.com
Guest
Posts: n/a
 
      12-17-2008
Hello:
I hope that my english will be readable, I have expended a lot of time
for writing this message

I have been using the validation controls in several applications.
After this I have not found a control for validating the form as a
whole and during the onsubmit event. I remember that in classic ASP I
did this without much effort. But now, I have tried with property
ValidationGroup, control CustomValidator or ValidationSummary, but I
always have a partial resolution for this problem. Perhaps, with
Javascript but finally I have problems with AJAX and other built-in
features.

I want to validate the controls only during the onsubmit event, not
before.

Anyone know a server control or similar that lets do this in a simple
way, and without problems with the rest of the ASP.NET?

Thanks.
 
Reply With Quote
 
 
 
 
S. Justin Gengo
Guest
Posts: n/a
 
      12-17-2008
Sergio,

If I understand, you want to stop individual control validation when moving
from one control to the other. And you also want to validate a certain group
of controls on a page.

To stop validation when moving from one control to another the easiest way
to do so will be to turn off client side validation and only validate server
side. Do this by setting EnableClientScript to False.

To group controls for validation so that you can have separate validation
when two different buttons are clicked set the ValidationGroup to the same
string value for all validators and the button you want to validate on the
same button click.

--
Sincerely,

S. Justin Gengo, MCP
Web Developer

Free code library at:
www.aboutfortunate.com

"Out of chaos comes order."
Nietzsche




<> wrote in message
news:f6959a16-8ab7-45a2-8c9e-...
> Hello:
> I hope that my english will be readable, I have expended a lot of time
> for writing this message
>
> I have been using the validation controls in several applications.
> After this I have not found a control for validating the form as a
> whole and during the onsubmit event. I remember that in classic ASP I
> did this without much effort. But now, I have tried with property
> ValidationGroup, control CustomValidator or ValidationSummary, but I
> always have a partial resolution for this problem. Perhaps, with
> Javascript but finally I have problems with AJAX and other built-in
> features.
>
> I want to validate the controls only during the onsubmit event, not
> before.
>
> Anyone know a server control or similar that lets do this in a simple
> way, and without problems with the rest of the ASP.NET?
>
> Thanks.


 
Reply With Quote
 
 
 
 
sergio.leon.leon@gmail.com
Guest
Posts: n/a
 
      12-19-2008
Hi Justin:

Finally, I think that I found a simple solution for this. I hope that
it will be a good solution.

1. Don't use validator controls for any controls.
2. Only use a CustomValidator control. Furthermore, it will be a
novisible control (with top: -500px for example).
3. Do the entire validation in the code of this last validator
control.

Something like this:

<%@ Page Language="VB" AutoEventWireup="false"
CodeFile="Default4.aspx.vb" Inherits="Default4" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://
www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>

<script language="javascript" type="text/javascript">
function validacionFormulario(sender, e) {
//debugger
var s = "";
var r = true;
if (!($get("<%=TextBox1.ClientID%>").value)) {
s += "TextBox1 is required.\n";
r = false;
}
if (!($get("<%=TextBox2.ClientID%>").value)) {
s += "TextBox2 is required.\n";
r = false;
}
if (!($get("<%=TextBox3.ClientID%>").value)) {
s += "TextBox3 is required.\n";
r = false;
}
if (!($get("<%=TextBox4.ClientID%>").value)) {
s += "TextBox4 is required.\n";
r = false;
}
e.IsValid = r;
if (!r)
alert(s);
}
</script>

<style type="text/css">
.dummy
{
position: absolute;
top: -5000px;
}
</style>
</head>
<body>
<form id="form1" runat="server">
<asp:ScriptManager ID="ScriptManager1" runat="server">
</asp:ScriptManager>
<div>
<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
<br />
<asp:TextBox ID="TextBox2" runat="server"></asp:TextBox>
<br />
<asp:TextBox ID="TextBox3" runat="server"></asp:TextBox>
<br />
<asp:TextBox ID="TextBox4" runat="server"></asp:TextBox>
<br />
<asp:TextBox ID="TextBox5" runat="server" ReadOnly="true"
CssClass="dummy"></asp:TextBox>
<br />
<asp:Button ID="Button1" runat="server" Text="Button" />
<asp:CustomValidator ID="CustomValidator1" runat="server"
ControlToValidate="TextBox5"
Display="None" ErrorMessage="CustomValidator"
ClientValidationFunction="validacionFormulario"
SetFocusOnError="false" ValidateEmptyText="true"></
asp:CustomValidator>
</div>
</form>
</body>
</html>


On 17 dic, 13:53, "S. Justin Gengo" <justin[remove-to-mail]@about-
delete-to-mail-fortunate.com> wrote:
> Sergio,
>
> If I understand, you want to stop individual control validation when moving
> from one control to the other. And you also want to validate a certain group
> of controls on a page.
>
> To stop validation when moving from one control to another the easiest way
> to do so will be to turn off client side validation and only validate server
> side. Do this by setting EnableClientScript to False.
>
> To group controls for validation so that you can have separate validation
> when two different buttons are clicked set the ValidationGroup to the same
> string value for all validators and the button you want to validate on the
> same button click.
>
> --
> Sincerely,
>
> S. Justin Gengo, MCP
> Web Developer
>
> Free code library at:www.aboutfortunate.com
>
> "Out of chaos comes order."
> Nietzsche
>
> <sergio.leon.l...@gmail.com> wrote in message
>
> news:f6959a16-8ab7-45a2-8c9e-...
>
>
>
> > Hello:
> > I hope that my english will be readable, I have expended a lot of time
> > for writing this message

>
> > I have been using the validation controls in several applications.
> > After this I have not found a control for validating the form as a
> > whole and during the onsubmit event. I remember that in classic ASP I
> > did this without much effort. But now, I have tried with property
> > ValidationGroup, control CustomValidator or ValidationSummary, but I
> > always have a partial resolution for this problem. Perhaps, with
> > Javascript but finally I have problems with AJAX and other built-in
> > features.

>
> > I want to validate the controls only during the onsubmit event, not
> > before.

>
> > Anyone know a server control *or similar that lets do this in a simple
> > way, and without problems with the rest of the ASP.NET?

>
> > Thanks.- Ocultar texto de la cita -

>
> - Mostrar texto de la cita -


 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Convert form to submit on load instead of clicking submit button? Network-Man HTML 5 07-07-2012 12:06 PM
submit 1 form to 2 servers or 2 forms to 2 server (1 form each) on 1 submit abansal.itp@gmail.com Javascript 3 06-23-2007 07:29 AM
Catching Submit Event even called by document.forms[0].submit() The Crow ASP .Net 2 09-27-2005 05:03 PM
submit form, validate form, set cookie, send email, download file mhawkins19@adelphia.net Javascript 1 03-17-2005 08:19 AM
submit the form data to the popup window without a submit button jrefactors@hotmail.com HTML 2 01-01-2005 06:07 AM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57