473,382 Members | 1,368 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,382 software developers and data experts.

RequiredFieldValidator: cannot disable/set invisible in datagrid

--Background:
I have a webform including a datagrid. The datagrid is using template. Its
ItemTemplate is used to display a look-up-table with labels. its
EditItemTemplate is used to edit a row in the look-up-table with textboxes. I
have a linkbutton in each row (causevalidation = false) named 'Edit' to post
the page back such that the page is switch from display mode to edit mode
(labels -> textboxes for the row to be edited), and the textboxes, are
associated with a group of validators (call them Edit-Validators). At the
same time, I have one row of textboxes in the FooterTemplate, which is for
the user to add one record to the look-up-table. And this footer template is
displayed in both modes through the postback. A set of requiredfield
validator are set for this row (call them Add-Validators).
--Objective:
When clicking the 'Edit' linkbutton in anyrow, I want the Add-validators to
be disabled. So I set all the "visible" properties to be false for all
Add-validators in the itemcommand event, which is triggered by the 'Edit'
linkbutton. But when the page is rendered in the client after the postback
(Now the 'Edit' LinkButton is replaced by a 'Save' LinkButton with
causevalidation=true), and when i click the Save LinkButton, the validators
in Add-Validators are still checked in client-side script.
--Summary
The state of the requiredfieldvalidator are not saved in viewstate across
page postback in above scenario
--Debug:
From debug information, in the first postback the visible property of
requiredfieldvalidators are set to false successfully. But in the second
postback, it is true again. Means the state information is not kept in
viewstate but it should be.
--Testing case:
I have tried this with a simple project, with similar scenario without
datagrid(only 2 textboxes eaching having a requiredfieldvalidators
associated, and two buttons, A to trigger the postback to disable one
validator, B to test the validation). It works fine. The validators are
disabled when setting the visible to false in server side code triggered by
the first button A.
--Question
Why the requiredfieldvalidator can be disabled in my simple testing, but
does not work in the datagrid?
--Thanks in advance, folks
let me know if you want to know more

Nov 18 '05 #1
2 5902
Hi,

Most probably after you set the Visible properties of the validators you
call DataBind, which reinstantiates the controls (in fact clears the control
collection of the datagrid and rebuilds it). Try setting Visible to false
after you call DataBind on the datagrid.

Hope this helps
Martin
"Fluxray" <Fl*****@discussions.microsoft.com> wrote in message
news:B9**********************************@microsof t.com...
--Background:
I have a webform including a datagrid. The datagrid is using template. Its
ItemTemplate is used to display a look-up-table with labels. its
EditItemTemplate is used to edit a row in the look-up-table with textboxes. I have a linkbutton in each row (causevalidation = false) named 'Edit' to post the page back such that the page is switch from display mode to edit mode
(labels -> textboxes for the row to be edited), and the textboxes, are
associated with a group of validators (call them Edit-Validators). At the
same time, I have one row of textboxes in the FooterTemplate, which is for
the user to add one record to the look-up-table. And this footer template is displayed in both modes through the postback. A set of requiredfield
validator are set for this row (call them Add-Validators).
--Objective:
When clicking the 'Edit' linkbutton in anyrow, I want the Add-validators to be disabled. So I set all the "visible" properties to be false for all
Add-validators in the itemcommand event, which is triggered by the 'Edit'
linkbutton. But when the page is rendered in the client after the postback
(Now the 'Edit' LinkButton is replaced by a 'Save' LinkButton with
causevalidation=true), and when i click the Save LinkButton, the validators in Add-Validators are still checked in client-side script.
--Summary
The state of the requiredfieldvalidator are not saved in viewstate across
page postback in above scenario
--Debug:
From debug information, in the first postback the visible property of
requiredfieldvalidators are set to false successfully. But in the second
postback, it is true again. Means the state information is not kept in
viewstate but it should be.
--Testing case:
I have tried this with a simple project, with similar scenario without
datagrid(only 2 textboxes eaching having a requiredfieldvalidators
associated, and two buttons, A to trigger the postback to disable one
validator, B to test the validation). It works fine. The validators are
disabled when setting the visible to false in server side code triggered by the first button A.
--Question
Why the requiredfieldvalidator can be disabled in my simple testing, but
does not work in the datagrid?
--Thanks in advance, folks
let me know if you want to know more

Nov 18 '05 #2
Martin:

Firstly thank you for your immediate reply :D
You are right.
One more finding is that I must get the DataGridItem after the databind,
then i call findcontrol to get a reference to the requiredfieldvalidator. I
think it is because the Datagriditem is dynamically reinstantiate on each
page generation. Microsoft generated all DataGridItem since the number of
rows varies, including the page footer, which actually need not to be
reinstantiated as there is only one footer at all the time.

"Martin Dechev" wrote:
Hi,

Most probably after you set the Visible properties of the validators you
call DataBind, which reinstantiates the controls (in fact clears the control
collection of the datagrid and rebuilds it). Try setting Visible to false
after you call DataBind on the datagrid.

Hope this helps
Martin
"Fluxray" <Fl*****@discussions.microsoft.com> wrote in message
news:B9**********************************@microsof t.com...
--Background:
I have a webform including a datagrid. The datagrid is using template. Its
ItemTemplate is used to display a look-up-table with labels. its
EditItemTemplate is used to edit a row in the look-up-table with

textboxes. I
have a linkbutton in each row (causevalidation = false) named 'Edit' to

post
the page back such that the page is switch from display mode to edit mode
(labels -> textboxes for the row to be edited), and the textboxes, are
associated with a group of validators (call them Edit-Validators). At the
same time, I have one row of textboxes in the FooterTemplate, which is for
the user to add one record to the look-up-table. And this footer template

is
displayed in both modes through the postback. A set of requiredfield
validator are set for this row (call them Add-Validators).
--Objective:
When clicking the 'Edit' linkbutton in anyrow, I want the Add-validators

to
be disabled. So I set all the "visible" properties to be false for all
Add-validators in the itemcommand event, which is triggered by the 'Edit'
linkbutton. But when the page is rendered in the client after the postback
(Now the 'Edit' LinkButton is replaced by a 'Save' LinkButton with
causevalidation=true), and when i click the Save LinkButton, the

validators
in Add-Validators are still checked in client-side script.
--Summary
The state of the requiredfieldvalidator are not saved in viewstate across
page postback in above scenario
--Debug:
From debug information, in the first postback the visible property of
requiredfieldvalidators are set to false successfully. But in the second
postback, it is true again. Means the state information is not kept in
viewstate but it should be.
--Testing case:
I have tried this with a simple project, with similar scenario without
datagrid(only 2 textboxes eaching having a requiredfieldvalidators
associated, and two buttons, A to trigger the postback to disable one
validator, B to test the validation). It works fine. The validators are
disabled when setting the visible to false in server side code triggered

by
the first button A.
--Question
Why the requiredfieldvalidator can be disabled in my simple testing, but
does not work in the datagrid?
--Thanks in advance, folks
let me know if you want to know more


Nov 18 '05 #3

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

Similar topics

3
by: Alphonse Giambrone | last post by:
I am trying to enable/disable a requiredfieldvalidator on the client side and am generating an error. I had found some documentation on validation which states that I should be able to...
3
by: Igor Mendizabal | last post by:
Hello, We're doing our own datagrid based on the System.windows.forms.datagrid control, and are having some problems with horizontal scrolling. In general, we construct our datagrid adding a...
3
by: Navin | last post by:
Hello friends... On a single asp.net web page i have a single server-side form that contains a couple of user-controls. Each user control has its own functionality and contains server-side textbox...
2
by: RSB | last post by:
Hi all, i have this form with the NewText Fields and then the Editable datagrid for all the existing Records. So i have to Buttons "Add New" and "Save Changes" and there is a Set of Validations...
3
by: Richard | last post by:
After printing a userlist to a Datagrid i want some names not to be shown. I want to know how i can make a entire datagrid row invisible. I suspect its something with the OnItemDatabound but i am...
2
by: Paul Hethmon | last post by:
I've got a strange behavior on a new machine. I cannot get a web page with a RequiredFieldValidator to submit the form. My test case is simply a new project, add a textbox, a label, a button,...
5
by: Hazz | last post by:
I needed to provide client side validation for a web forms text box, radio button list, and drop down list. I asked two developers I work with what they thought I should do. One said Javascript,...
1
by: Giovanni | last post by:
Dear Friends, I need your help. I am trying to dynamically create a RequiredFieldValidator in the ItemCreated event of a DataList but cannot get it to work. The errors seem to revolve around...
3
by: rockdale | last post by:
Hi, All: I have a datagrid with TemplateColumn as following: <asp:TemplateColumn Visible="False" > <ItemStyle Width="0px"></ItemStyle> <ItemTemplate> <asp:Label id="lblMin_Value"...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
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...

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.