By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
425,966 Members | 812 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 425,966 IT Pros & Developers. It's quick & easy.

Validator fails after enabling

P: n/a
I'm trying to dynamically hide/show a HTML table server control.
My form contains one CheckBox control and its AutoPostBack set to true.
The Checked value of this box controls whether to show or hide the table.
Initially this CheckBox is not checked, so the table and all web control it
contains
is not rendered to a client. The table contains several TextBox controls and
each TextBox has a pair of RequiredFieldValidator and CompareValidator.
When I click the previous checkbox, the form postbacks and the server side
code sets HtmlTable.Visible to true. Now all TextBoxes appear at the client
side,
BUT ALL validators indicate failure by showing theirs Text message. Why?
When I do not hide/show the table and it is always visible, the validators
work normally.
This only happens when the table and its content (the textboxes and
validators)
are dynamically showed/rendered. As I know, the CheckBox's AutoPostBack
does not trigger a validation process. Any ideas?
I tried to trace my page and set several breakpoints at Page_Load, PreRender
and
CheckBox_CheckedChanged. At these points I checked values of the IsValid
properties
of the validators. They were always TRUE. I wonder when they switches to
FALSE?
If I'm right, a validator displays the Text only when IsValid is false. Yes?

Nov 20 '05 #1
Share this Question
Share on Google+
3 Replies


P: n/a
You cannot validate against the CheckBox or CheckBoxList server controls
using the RequiredFieldValidator server control. Instead you need to use the
CustomValidator server control.
Look though :- http://www.syncfusion.com/FAQ/aspnet/WEB_c18c.aspx
Hope that helps
Patrick

"Tumurbaatar S." <sp********@magicnet.mn> wrote in message
news:ev**************@TK2MSFTNGP10.phx.gbl...
I'm trying to dynamically hide/show a HTML table server control.
My form contains one CheckBox control and its AutoPostBack set to true.
The Checked value of this box controls whether to show or hide the table.
Initially this CheckBox is not checked, so the table and all web control it contains
is not rendered to a client. The table contains several TextBox controls and each TextBox has a pair of RequiredFieldValidator and CompareValidator.
When I click the previous checkbox, the form postbacks and the server side
code sets HtmlTable.Visible to true. Now all TextBoxes appear at the client side,
BUT ALL validators indicate failure by showing theirs Text message. Why?
When I do not hide/show the table and it is always visible, the validators
work normally.
This only happens when the table and its content (the textboxes and
validators)
are dynamically showed/rendered. As I know, the CheckBox's AutoPostBack
does not trigger a validation process. Any ideas?
I tried to trace my page and set several breakpoints at Page_Load, PreRender and
CheckBox_CheckedChanged. At these points I checked values of the IsValid
properties
of the validators. They were always TRUE. I wonder when they switches to
FALSE?
If I'm right, a validator displays the Text only when IsValid is false. Yes?

Nov 21 '05 #2

P: n/a
I'm sorry. I did not clearly explain the scenario.
There's a HtmlTable with TextBoxes and Validators (Required and Compare).
When the table is visible (I show it by "HtmlTable.Visible = true") and ALL
its rows (where textboxes and validators) are visible too, the validators
work
normally. When I show the table, but hide SOME rows
(HtmlTable.Rows[i].Visible = false),
then the validators located within visible rows work ok. But in next
roundtrip
I show previously hidden rows (HtmlTable.Rows[i].Visible = true). And the
validators
that were hidden in prior step, appear as FAILED: theirs error texts are
shown.
Though these validators works normally (properly detects blank or invalid
values),
only they initially appears with visible errors. The validators that were
visible already
are not have any problem.
I've done here some more tests and found that is not related to a validation
process.
Even the validators are disabled (Enabled = false), they re-appears with
visible errors
texts.
I found some workaround, but it does not really solve the problem, only
makes
the problem hidden.
Instead of resetting HtmlTable.Rows[i].Visible properties, I apply CSS
attribute "display" with "none" or "block" values to the rows. In this case,
the hidden rows and controls are rendered to a client, only they are
invisible.
So I need to disable the validators before.
Below is my new method to hide/show rows:

private void ToggleRows(bool Visible)
{
//this is an array of textboxes and validators located in hidden
rows
WebControl[] ctrls =
{
Trans20Txt, Trans20Val1, Trans20Val2,
Trans40Txt, Trans40Val1, Trans40Val2,
Trans00Txt, Trans00Val1, Trans00Val2
};
string display = Visible? "block" : "none";

for (int i = 0; i < ctrls.Length; i++)
ctrls[i].Enabled = Visible;
for (int i = 3; i < FormTbl.Rows.Count - 1; i++)
FormTbl.Rows[i].Style["display"] = display;
}

My old method was shorter and simpler:

private void ToggleRows(bool Visible) // no reason to disable validators
{
for (int i = 3; i < FormTbl.Rows.Count - 1; i++)
FormTbl.Rows[i].Visible = Visible;
}

P.S. The checkbox I mentioned in prior post, I use to as a trigger of
visibility of the table.
"Patrick.O.Ige" <na********@hotmail.com> wrote in message
news:uU**************@TK2MSFTNGP14.phx.gbl...
You cannot validate against the CheckBox or CheckBoxList server controls
using the RequiredFieldValidator server control. Instead you need to use
the
CustomValidator server control.
Look though :- http://www.syncfusion.com/FAQ/aspnet/WEB_c18c.aspx
Hope that helps
Patrick

"Tumurbaatar S." <sp********@magicnet.mn> wrote in message
news:ev**************@TK2MSFTNGP10.phx.gbl...
I'm trying to dynamically hide/show a HTML table server control.
My form contains one CheckBox control and its AutoPostBack set to true.
The Checked value of this box controls whether to show or hide the table.
Initially this CheckBox is not checked, so the table and all web control

it
contains
is not rendered to a client. The table contains several TextBox controls

and
each TextBox has a pair of RequiredFieldValidator and CompareValidator.
When I click the previous checkbox, the form postbacks and the server
side
code sets HtmlTable.Visible to true. Now all TextBoxes appear at the

client
side,
BUT ALL validators indicate failure by showing theirs Text message. Why?
When I do not hide/show the table and it is always visible, the
validators
work normally.
This only happens when the table and its content (the textboxes and
validators)
are dynamically showed/rendered. As I know, the CheckBox's AutoPostBack
does not trigger a validation process. Any ideas?
I tried to trace my page and set several breakpoints at Page_Load,

PreRender
and
CheckBox_CheckedChanged. At these points I checked values of the IsValid
properties
of the validators. They were always TRUE. I wonder when they switches to
FALSE?
If I'm right, a validator displays the Text only when IsValid is false.

Yes?




Nov 21 '05 #3

P: n/a
When a Validator's IsValid property is false at the time of Render, it
writes out its error message. A call to Page.Validate() will update IsValid
on each validator. That call should happen before OnPreRender, so if IsValid
is true while debugging PreRender, we must look for another cause.

When validators output themselves, they are always a <span> tag containing
the error message. To keep them initially hidden, they include
style="visibility:hidden" (when Display="Static") or
style="visibility:hidden;display:none" (when Display="Dynamic"). I am
wondering if your HTML includes this style or not. In any case, look
carefully at the HTML generated to try to locate the source of it becoming
visible. There may be a style sheet problem.
--- Peter Blum
www.PeterBlum.com
Email: PL****@PeterBlum.com
Creator of "Professional Validation And More" at
http://www.peterblum.com/vam/home.aspx

"Tumurbaatar S." <sp********@magicnet.mn> wrote in message
news:ev**************@TK2MSFTNGP10.phx.gbl...
I'm trying to dynamically hide/show a HTML table server control.
My form contains one CheckBox control and its AutoPostBack set to true.
The Checked value of this box controls whether to show or hide the table.
Initially this CheckBox is not checked, so the table and all web control
it contains
is not rendered to a client. The table contains several TextBox controls
and
each TextBox has a pair of RequiredFieldValidator and CompareValidator.
When I click the previous checkbox, the form postbacks and the server side
code sets HtmlTable.Visible to true. Now all TextBoxes appear at the
client side,
BUT ALL validators indicate failure by showing theirs Text message. Why?
When I do not hide/show the table and it is always visible, the validators
work normally.
This only happens when the table and its content (the textboxes and
validators)
are dynamically showed/rendered. As I know, the CheckBox's AutoPostBack
does not trigger a validation process. Any ideas?
I tried to trace my page and set several breakpoints at Page_Load,
PreRender and
CheckBox_CheckedChanged. At these points I checked values of the IsValid
properties
of the validators. They were always TRUE. I wonder when they switches to
FALSE?
If I'm right, a validator displays the Text only when IsValid is false.
Yes?


Nov 21 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.