--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 2 5740
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
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 This discussion thread is closed Replies have been disabled for this discussion. Similar topics
3 posts
views
Thread by Alphonse Giambrone |
last post: by
|
3 posts
views
Thread by Igor Mendizabal |
last post: by
|
3 posts
views
Thread by Navin |
last post: by
|
2 posts
views
Thread by RSB |
last post: by
|
3 posts
views
Thread by Richard |
last post: by
|
2 posts
views
Thread by Paul Hethmon |
last post: by
|
5 posts
views
Thread by Hazz |
last post: by
|
1 post
views
Thread by Giovanni |
last post: by
|
3 posts
views
Thread by rockdale |
last post: by
| | | | | | | | | | |