Based on the content in my database, I need to populate different form
controls and validators, such as textbox, dropdownlist,
requiredfieldva lidators , etc.
Then I need to check if the form has been filled out correctly. If so, I
need to update a database, and do other things.
In order to check if the form is ok, I've tried looping through the
validator controls, and I've also tried using page.isvalid.
Nomatter what, the form seems to be incorrrectly filled out. The validator
controls comes out as "false", and Page.isvalid also comes out as false.
Regards C.H
Here is a modified example of my problem, so that you can see what I'm
dealing with.
<%@ Page language="c#" Codebehind="tes tfil1.aspx.cs" AutoEventWireup ="false"
Inherits="smbuC lass.testfil1" Trace=true enableViewState =false %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" >
<HTML>
<HEAD>
<title>testfil1 </title>
<meta name="GENERATOR " Content="Micros oft Visual Studio 7.0">
<meta name="CODE_LANG UAGE" Content="C#">
<meta name="vs_defaul tClientScript" content="JavaSc ript">
<meta name="vs_target Schema"
content="http://schemas.microso ft.com/intellisense/ie5">
</HEAD>
<body MS_POSITIONING= "GridLayout ">
<form runat="server" ID="Form1" method="post" action="testfil 1.aspx">
<asp:placeholde r id="plh" runat="server" />
<asp:button Text="Click" runat="server" CausesValidatio n="true"
ID="Button" />
</form>
</body>
</HTML>
using System;
using System.Data;
using System.Web.UI;
using System.Web.UI.W ebControls;
using System.Collecti ons;
namespace smbuClass
{
public class testfil1 : System.Web.UI.P age
{
protected RequiredFieldVa lidator validator2 = new
RequiredFieldVa lidator();
protected TextBox txtfield=new TextBox();
protected System.Web.UI.W ebControls.Butt on Button;
protected PlaceHolder plh;
private void Page_Load(Objec t sender,EventArg s e)
{
txtfield.ID="tx tfield";
plh.Controls.Ad d(txtfield);
validator2.Cont rolToValidate=t xtfield.ID+"";
validator2.ID=" validator2";
validator2.Text = "Error";
validator2.Erro rMessage="Error ";
validator2.Enab leClientScript= false;
plh.Controls.Ad d(validator2);
if(Page.IsPostB ack)
{
Page.Validate() ;
if(Page.IsValid )
Response.Write( "all ok");
else
Response.Write( "not ok");
foreach(BaseVal idator b in Page.Validators )
{
Trace.Warn(b.Is Valid + " " +b.ID + " ");
}
}
}
override protected void OnInit(EventArg s e)
{
//
// CODEGEN: This call is required by the ASP.NET Web Form Designer.
//
InitializeCompo nent();
base.OnInit(e);
}
private void InitializeCompo nent()
{
this.Load += new System.EventHan dler(this.Page_ Load);
}
}
} 2 6492
I go track of the error now.
Change the code like this:
protected override void CreateChildCont rols()
{
RequiredFieldVa lidator validator2 = new RequiredFieldVa lidator();
TextBox txtfield=new TextBox();
txtfield.ID="tx tfield";
plh.Controls.Ad d(txtfield);
plh.Controls.Ad d(validator2);
validator2.Cont rolToValidate=t xtfield.ID;
validator2.ID=" validator2";
validator2.Text = "Error";
validator2.Erro rMessage="Error ";
validator2.Enab leClientScript= false;
}
Just add this overridden CreateChildCont rols to the Page and remove the
relevant code from Page_Load. That should do it. (Page.Validate etc can
still be where they are now)
--
Teemu Keiski
MCP, Designer/Developer
Mansoft tietotekniikka Oy http://www.mansoft.fi
AspInsiders Member, www.aspinsiders.com
ASP.NET Forums Moderator, www.asp.net
AspAlliance Columnist, www.aspalliance.com
"Christian H" <no@name.no> wrote in message
news:uD******** ******@TK2MSFTN GP10.phx.gbl... Based on the content in my database, I need to populate different form controls and validators, such as textbox, dropdownlist, requiredfieldva lidators , etc.
Then I need to check if the form has been filled out correctly. If so, I need to update a database, and do other things.
In order to check if the form is ok, I've tried looping through the validator controls, and I've also tried using page.isvalid.
Nomatter what, the form seems to be incorrrectly filled out. The validator controls comes out as "false", and Page.isvalid also comes out as false.
Regards C.H
Here is a modified example of my problem, so that you can see what I'm dealing with.
<%@ Page language="c#" Codebehind="tes tfil1.aspx.cs"
AutoEventWireup ="false" Inherits="smbuC lass.testfil1" Trace=true enableViewState =false %> <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" > <HTML> <HEAD> <title>testfil1 </title> <meta name="GENERATOR " Content="Micros oft Visual Studio 7.0"> <meta name="CODE_LANG UAGE" Content="C#"> <meta name="vs_defaul tClientScript" content="JavaSc ript"> <meta name="vs_target Schema" content="http://schemas.microso ft.com/intellisense/ie5"> </HEAD> <body MS_POSITIONING= "GridLayout "> <form runat="server" ID="Form1" method="post" action="testfil 1.aspx"> <asp:placeholde r id="plh" runat="server" /> <asp:button Text="Click" runat="server" CausesValidatio n="true" ID="Button" /> </form> </body> </HTML>
using System; using System.Data; using System.Web.UI; using System.Web.UI.W ebControls; using System.Collecti ons;
namespace smbuClass { public class testfil1 : System.Web.UI.P age {
protected RequiredFieldVa lidator validator2 = new RequiredFieldVa lidator(); protected TextBox txtfield=new TextBox(); protected System.Web.UI.W ebControls.Butt on Button; protected PlaceHolder plh;
private void Page_Load(Objec t sender,EventArg s e) {
txtfield.ID="tx tfield"; plh.Controls.Ad d(txtfield);
validator2.Cont rolToValidate=t xtfield.ID+""; validator2.ID=" validator2"; validator2.Text = "Error"; validator2.Erro rMessage="Error "; validator2.Enab leClientScript= false; plh.Controls.Ad d(validator2);
if(Page.IsPostB ack) { Page.Validate() ; if(Page.IsValid ) Response.Write( "all ok"); else Response.Write( "not ok");
foreach(BaseVal idator b in Page.Validators ) { Trace.Warn(b.Is Valid + " " +b.ID + " "); }
}
}
override protected void OnInit(EventArg s e) { // // CODEGEN: This call is required by the ASP.NET Web Form Designer. // InitializeCompo nent(); base.OnInit(e); }
private void InitializeCompo nent() { this.Load += new System.EventHan dler(this.Page_ Load);
}
} }
Thank you!
I need some advice on what to read in order to learn more about these
things.
Why did I need to override that method, and how will I know when I will need
to override a method next time...?
I've got a feeling I'm going to need to override methods a lot with this
project
Do you have an book suggestion, or online tutorials that will educate me on
this?
Regards Christian H. 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: -=Chris=- |
last post by:
I'm developing a custom server control that will be rendering a form based
on some input. I've tried creating custom validators in vb.net like so:
Dim v1 as RequiredValidator = new RequiredValidator()
Dim vs as ValidationSummary = new ValidationSummary()
RequiredValidator.ControlToValidate = "id of form control here"
RequiredValidator.Enabled = True
RequiredValidator.EnableClientScript = True
RequiredValidator.ErrorMessage = "Test...
|
by: Tony |
last post by:
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 programmatically create a control and a required field
validator, and don't use client side validation,...
|
by: Donald Xie |
last post by:
Hi,
I noticed an interesting effect when working with controls that are
dynamically loaded. For instance, on a web form with a PlaceHolder control
named ImageHolder, I dynamically add an image button at runtime:
//----- Code snippet
protected System.Web.UI.WebControls.PlaceHolder ImageHolder;
private void Page_Load(object sender, System.EventArgs e)
|
by: Andy Fish |
last post by:
Hi,
Although I have got to the bottom of this problem, it gave me quite a shock
to discover how easy it is to write a very unsafe application with .Net
validators.
The scenario was this: we wrote and tested an application using validators,
but when we deployed the app onto a different server, it accepted and
processed invalid input from the user.
| |
by: Jack |
last post by:
Hi,
I have a page with a repeater control that contains textboxes. I'm trying
to create a validation class that is called by my page. A method in this
class iterates through all the controls on the page. On encountering a
TextBox control, it looks at the ID to discern the field the TextBox
represents, and then creates the appropriate validation controls and adds
them to the page. The controlToValidate property of each validation...
|
by: LU |
last post by:
I query database,
QuestionID | QuestionName | QuestionType
1 | FirstName | TextBox
2 | LastName | TextBox
Loop
Create TextBox
Create RequiredFieldValidator
Here is my problem.
|
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: sydney.luu |
last post by:
Hello,
I would greatly appreciate if someone can show me how to dynamically
build a Repeater
with unknown number of columns at design time. I have looked various
threads in this
newsgroup, websites, MSDN and was not able to find something that would
help me understand and code. I might not be searching for the right
words or phrases. So if you know how to do this or know of links or
websites that have information about this, please...
|
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: 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...
| |
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: 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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
|
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: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules.
He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms.
Adolph will...
|
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: 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...
| |