473,407 Members | 2,314 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,407 software developers and data experts.

dynamic generation of a CustomValidator

Hello everybody,

I have a problem concerning the dynamic creation of a CustomValidator.

If I create a CustomControl as shown in the code below and the page is post
back the validation procedure is never called.

In Page_Load Page Validate() is called and in the control which should be
validated there is a non numeric value.

Why is the procedure "checkProd" never calles? What's wrong?

Here the code extract:

cell = New HtmlTableCell
txt = New HtmlInputText
txt.ID = "txt1"

val = New CustomValidator
val.EnableClientScript = False
val.Text = "*"
val.ErrorMessage = "Eingabe ungültig"
val.ControlToValidate = "txt1"
AddHandler val.ServerValidate, AddressOf checkProd

cell.Controls.Add(val)

...

Protected Sub checkProd(ByVal source As Object, ByVal args As
ServerValidateEventArgs)
If Not IsNumeric(args.Value) Then
args.IsValid = False
Else
args.IsValid = True
End If
End Sub

Thank you and best regards

Markus

Nov 19 '05 #1
5 4496
Maybe try adding your control during the MyBase/Page.Init event. Also
make sure you're only adding it when Page.IsPostback = False

Nov 19 '05 #2
Both has not solved the problem ;-)
"ajamrozek" <aj*******@msn.com> schrieb im Newsbeitrag
news:11*********************@g14g2000cwa.googlegro ups.com...
Maybe try adding your control during the MyBase/Page.Init event. Also
make sure you're only adding it when Page.IsPostback = False

Nov 19 '05 #3
Well this is kind of a hack and not as efficient as possible, but I've
had to do it before.
Add all the controls you think you'll need to the page in a static
fashion with enabled and visible set to false, then set visibile and
enabled to true when you need to in the code behind. That should do
trick. You should be able to dynamically control the text and
errormessage for these, but they'll be on the page when it first loads.

Nov 19 '05 #4
"ajamrozek" wrote:
Maybe try adding your control during the MyBase/Page.Init event. Also
make sure you're only adding it when Page.IsPostback = False


Actually, dynamic controls should be added to the page *every* time. If you
don't recreate the control on the postback there's nothing to fire the events.
I like to create my dynamic controls as early in processing as is
reasonable; I recommend either doing it from the Init or by overriding
CreateChildControls (since that seems appropriately named if nothing else!).
Nov 19 '05 #5
> Actually, dynamic controls should be added to the page *every* time. If
you
don't recreate the control on the postback there's nothing to fire the

events.

That was the point. Now it works ;-)

But recreating is not comfortable :-(

Thank you all
Nov 19 '05 #6

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

Similar topics

7
by: jcpmeticulus | last post by:
Hi I've spent the last day or so debugging a problem with a CustomValidator and am now totally stumped! Basically I use a number of CustomValidator's on my page, but have cut this down now to...
11
by: Marco Loskamp | last post by:
Dear list, I'm trying to dynamically generate functions; it seems that what I really want is beyond C itself, but I'd like to be confirmed here. In the minimal example below, I'd like to...
2
by: Stephen Miller | last post by:
Can the CustomValidator be used to simply report unexpected errors, without requiring Client/Server validation? To explain, say you had a simple text box and button that did a Full-text Search of a...
1
by: SMG | last post by:
Hi All. My forms has two textboxes, 1 username, 2 password. Both has requiredfield validator it works fine when there is no input in these textboxes. And the errorMsg is shown in...
1
by: theresa | last post by:
Hello. I'm creating a form that has (up to) 10 identical panels on the page, with each panel containing the same 8 textboxes for things like school name, address, etc, and one dropdown box. The...
4
by: TS | last post by:
I am creating a User control and i create some dynamic controls in the init handler. one of the controls is a custom validator which i assign a serverValidate event handler. I usally always do my...
2
by: Ghada Al-Mashaqbeh via DotNetMonster.com | last post by:
Hi all, I am facing a problem in dynamic code generation at run time, the problem occurs when the dynmaic code use global data exist within the original application. Lets say that my...
5
by: pittendrigh | last post by:
There must be millions of dynamically generated html pages out there now, built by on-the-fly php code (and jsp, perl cgi, asp, etc). Programatic page generation is transparently useful. But...
0
by: Eniac | last post by:
Hi, I've been working on a custom user control that needs to be modified and the validation is causing me headaches. The control used to generate a table of 4 rows x 7 columns to display all...
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
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...
0
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
isladogs
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...

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.