Hi folks,
I've got a bit of a problem. I have a situation where I build forms
completely dynamically based on a form definition supplied from a database.
Anyway, I noticed that required fields weren't validating on the server
side, so I've whittled the code down to the example below which illustrates
the problem.
Basically, when I programmaticall y create a control and a required field
validator, and don't use client side validation, the server side validation
is performed, but ignored - and my button's Click handler is still called. I
can obviously work around this by doing a if( ! Page.IsValid ) return in
the handler, but the validation system is supposed to ensure that if page
content isn't valid, the button's handler won't be called.....
In the example below, you'll see that the button handler DOES get called,
even though Page.IsValid is false. But here's something interesting - remove
the throw and the redirect from the handler, and you'll see that yes, the
handler still get's called, but when the processing has finished, the page
shows the errors as it should.....
anyway, the code is below, any help would be greatly appreciated, I'm about
to chuck my PC out the window with this one as I don't know whether I'm
doing something really daft or if I've discovered an "issue" in the
framework....
Cheers,
Tony
testit.aspx:
<%@ Page language="c#" Codebehind="val test.aspx.cs" AutoEventWireup ="false"
Inherits="trini ty.admin.develo per.sampler.val test" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" >
<HTML>
<body>
<form id="Form1" method="post" runat="server">
<asp:Validation Summary ID="_summary" ShowMessageBox= "True" Runat="server"/>
<asp:PlaceHolde r ID="_form" Runat="server"/>
<asp:Button ID="_save" Text="Save" Runat="server"/>
</form>
</body>
</HTML>
testit.aspx.cs:
using System;
using System.Collecti ons;
using System.Componen tModel;
using System.Data;
using System.Drawing;
using System.Web;
using System.Web.Sess ionState;
using System.Web.UI;
using System.Web.UI.W ebControls;
using System.Web.UI.H tmlControls;
namespace trinity.admin.d eveloper.sample r
{
/// <summary>
/// Summary description for valtest.
/// </summary>
public class valtest : System.Web.UI.P age
{
protected System.Web.UI.W ebControls.Text Box TextBox1;
protected System.Web.UI.W ebControls.Butt on Button1;
protected System.Web.UI.W ebControls.Vali dationSummary _summary;
protected System.Web.UI.W ebControls.Plac eHolder _form;
protected System.Web.UI.W ebControls.Butt on _save;
protected System.Web.UI.W ebControls.Requ iredFieldValida tor
RequiredFieldVa lidator1;
private void Page_Load(objec t sender, System.EventArg s e)
{
// Put user code to initialize the page here
TextBox b = new TextBox();
b.ID = "theTextBox ";
_form.Controls. Add(b);
RequiredFieldVa lidator v = new RequiredFieldVa lidator();
v.EnableClientS cript = false;
v.ControlToVali date = "theTextBox ";
v.ErrorMessage = "Problem";
v.ID = "thevalidat or";
_form.Controls. Add(v);
}
#region Web Form Designer generated code
override protected void OnInit(EventArg s e)
{
//
// CODEGEN: This call is required by the ASP.NET Web Form Designer.
//
InitializeCompo nent();
base.OnInit(e);
}
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeCompo nent()
{
this._save.Clic k += new System.EventHan dler(this._save _Click);
this.Load += new System.EventHan dler(this.Page_ Load);
}
#endregion
private void _save_Click(obj ect sender, System.EventArg s e)
{
if( ! Page.IsValid ) throw new Exception("I shouldn't get called here!");
Response.Redire ct("/", true);
}
}
} 1 3490
Update::::
Would appear that this behaviour is right. I've just done the same thing,
but declaratively - set EnabledClientSc ript=false on the validator and the
same thing happens. Looks like you have to test Page.IsValid on your button
handlers!
Cheers,
Tony
"Tony" <reply_to@newsg roup_only.net> wrote in message
news:VT******** **********@news-binary.blueyond er.co.uk... Hi folks,
I've got a bit of a problem. I have a situation where I build forms completely dynamically based on a form definition supplied from a
database. Anyway, I noticed that required fields weren't validating on the server side, so I've whittled the code down to the example below which
illustrates the problem.
Basically, when I programmaticall y create a control and a required field validator, and don't use client side validation, the server side
validation is performed, but ignored - and my button's Click handler is still called.
I can obviously work around this by doing a if( ! Page.IsValid ) return in the handler, but the validation system is supposed to ensure that if page content isn't valid, the button's handler won't be called.....
In the example below, you'll see that the button handler DOES get called, even though Page.IsValid is false. But here's something interesting -
remove the throw and the redirect from the handler, and you'll see that yes, the handler still get's called, but when the processing has finished, the page shows the errors as it should.....
anyway, the code is below, any help would be greatly appreciated, I'm
about to chuck my PC out the window with this one as I don't know whether I'm doing something really daft or if I've discovered an "issue" in the framework....
Cheers, Tony
testit.aspx: <%@ Page language="c#" Codebehind="val test.aspx.cs"
AutoEventWireup ="false" Inherits="trini ty.admin.develo per.sampler.val test" %> <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" > <HTML> <body>
<form id="Form1" method="post" runat="server"> <asp:Validation Summary ID="_summary" ShowMessageBox= "True"
Runat="server"/> <asp:PlaceHolde r ID="_form" Runat="server"/> <asp:Button ID="_save" Text="Save" Runat="server"/> </form> </body> </HTML>
testit.aspx.cs: using System; using System.Collecti ons; using System.Componen tModel; using System.Data; using System.Drawing; using System.Web; using System.Web.Sess ionState; using System.Web.UI; using System.Web.UI.W ebControls; using System.Web.UI.H tmlControls;
namespace trinity.admin.d eveloper.sample r { /// <summary> /// Summary description for valtest. /// </summary> public class valtest : System.Web.UI.P age { protected System.Web.UI.W ebControls.Text Box TextBox1; protected System.Web.UI.W ebControls.Butt on Button1; protected System.Web.UI.W ebControls.Vali dationSummary _summary; protected System.Web.UI.W ebControls.Plac eHolder _form; protected System.Web.UI.W ebControls.Butt on _save; protected System.Web.UI.W ebControls.Requ iredFieldValida tor RequiredFieldVa lidator1;
private void Page_Load(objec t sender, System.EventArg s e) { // Put user code to initialize the page here TextBox b = new TextBox(); b.ID = "theTextBox "; _form.Controls. Add(b);
RequiredFieldVa lidator v = new RequiredFieldVa lidator(); v.EnableClientS cript = false; v.ControlToVali date = "theTextBox "; v.ErrorMessage = "Problem"; v.ID = "thevalidat or";
_form.Controls. Add(v); }
#region Web Form Designer generated code override protected void OnInit(EventArg s e) { // // CODEGEN: This call is required by the ASP.NET Web Form Designer. // InitializeCompo nent(); base.OnInit(e); }
/// <summary> /// Required method for Designer support - do not modify /// the contents of this method with the code editor. /// </summary> private void InitializeCompo nent() { this._save.Clic k += new System.EventHan dler(this._save _Click); this.Load += new System.EventHan dler(this.Page_ Load);
} #endregion
private void _save_Click(obj ect sender, System.EventArg s e) { if( ! Page.IsValid ) throw new Exception("I shouldn't get called
here!"); Response.Redire ct("/", true); }
} }
This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: Trillium |
last post by:
I am trying to upgrade a straight ASP project into .NET, but I am new at
..NET, and there seem to be so many different ways to do things. I am new to
..NET and need some guidance as to which approach to take.
My application is to collect answers to an indeterminate number of
questions, which are defined in a database. The definition includes the
question content, type of control and validation for the data. In ASP, the
application...
|
by: Marina |
last post by:
Hi,
A very weird thing has happened. Today, all the validators on all the pages
and user controls on one of the servers stopped working. They seem to do
the validation server side, instead of client side. Other servers are
running the same code without a problem.
I compared the HTML output by the server causing the problem, and the one
that doesn't. It is identical other then some of the viewstate.
|
by: Jason Shohet |
last post by:
We coppied our site up to a 2003 remote server, and our validators stopped
working. I read on another posting, that the validation mechanism works by
examining some validation.js file in the web root folder, and the path to
this folder is in the web.config file??
I'm looking at the web.config file of the site, and don't see a path to some
folder, or some validation.js file.
Can someone help me out here. TY
Jason Shohet
|
by: interuser |
last post by:
I have an existing large application that uses validators.
I have a problem with the client side validators not working on
netscape (and any browser other than IE). As you may already know, the
reason is that the validators use document.all which is regognized
only by IE's javascript (as opposed to document.getElementById() which
is regognized by all browsers.)
I do not want to use validators other than dotnet's (it's the standard
of...
|
by: Jeffrey Todd |
last post by:
I have successfully created functionality that mostly models what I'm trying
to do - which is dynamically insert controls into a user control (ascx), and
insert validation controls, also dynamically, for some of the inserted
controls.
The controls (e.g., textBoxes) get created correctly and viewstate is
maintained across postbacks, etc - BUT there is an issue with the validation
controls.
The validation controls, themselves are...
| |
by: Jason |
last post by:
I am able fire my field validators in FireFox on the server side using...
Page.Validate()
If Not Page.IsValid Then
Exit Sub
End If
But the it won't fire Custom Validators. Anybody know why?
|
by: Gabriel Lozano-Morán |
last post by:
When using the tabstrip control combined with a multipage (several pageview)
there is a problem when using validators. The problem is that validation
also occurs on the validators that are not on the currently selected
pageview of the multipage. To prevent this from happening I disable all the
validators and only enable the validators on the selected page but does not
look to me like the correct way of working.
Is there a better way to...
|
by: ShaneFowlkes |
last post by:
For some reason, my validator controls stopped working when a form posts.
They seems to work on fields that lose focus but if I submit a form with all
empty fields, not of the required validators catch it and this results in
runtime errors with my code.
It's real standard stuff using .NET 2 (VB). I've stopped and restarted IIS
several times and I even re-registered the NET service using this at the
command prompt:...
|
by: Andrew Jocelyn |
last post by:
Hi
I have a Formview control in a UserControl. The server-side validation is
not working, i.e. the events are not firing when a button control which
causes validation is fired or even when Page.Validate() is explicitly
called.
I'm loading the FormView as an IBindableTemplate as in this article but I
don't think this is the reason for the validation not working.
http://www.developerfusion.co.uk/show/4721/
|
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...
|
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: 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: 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 then checking html paragraph one by one.
At the time of converting from word file to html my equations which are in the word document file was convert into image.
Globals.ThisAddIn.Application.ActiveDocument.Select();...
|
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.
| |