473,503 Members | 8,784 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Validating a hidden control?

Is it possible to have a validation control whose ControlToValidate is in
fact a hidden control? When I try this I find that the validator apparently
does not fire. If I make the control Visible="true", then the validator
fires as expected.

I realize that in a sense it doesn't make sense to validate such a control
since the user can't do anything (directly) to cure the problem. In my case
however the hidden control contains information representing a bit of state.
A simplified case would be that I don't want button A to submit until button
B has already been clicked (and the form submitted.) I "remember" whether
the form has had a "B submit" in a hidden field. I use validation groups to
differentiate between the two submit buttons.

Any suggestions?

Bill
Mar 4 '06 #1
6 1820
Hi Bill,

When you set a control's visible to false on server-side, the control
actually is not rendered to client-side. Hence the validator has nothing to
validate on client-side.

You should 'hidden' the control on client-side.

Suppose you want to hidden a textbox (ID = txtHidden), using following code
in Page_Load:

string hiddenTxt = "<script>var txt = document.getElementById('txtHidden');
txt.style.visibility='hidden';</script>";
Page.RegisterStartupScript("hidden", hiddenTxt);

HTH

Elton Wang

"Bill Cohagan" wrote:
Is it possible to have a validation control whose ControlToValidate is in
fact a hidden control? When I try this I find that the validator apparently
does not fire. If I make the control Visible="true", then the validator
fires as expected.

I realize that in a sense it doesn't make sense to validate such a control
since the user can't do anything (directly) to cure the problem. In my case
however the hidden control contains information representing a bit of state.
A simplified case would be that I don't want button A to submit until button
B has already been clicked (and the form submitted.) I "remember" whether
the form has had a "B submit" in a hidden field. I use validation groups to
differentiate between the two submit buttons.

Any suggestions?

Bill

Mar 5 '06 #2
Elton
Thanks for the suggestion. I'll give it a shot.

Bill

"Elton W" <El****@discussions.microsoft.com> wrote in message
news:36**********************************@microsof t.com...
Hi Bill,

When you set a control's visible to false on server-side, the control
actually is not rendered to client-side. Hence the validator has nothing
to
validate on client-side.

You should 'hidden' the control on client-side.

Suppose you want to hidden a textbox (ID = txtHidden), using following
code
in Page_Load:

string hiddenTxt = "<script>var txt =
document.getElementById('txtHidden');
txt.style.visibility='hidden';</script>";
Page.RegisterStartupScript("hidden", hiddenTxt);

HTH

Elton Wang

"Bill Cohagan" wrote:
Is it possible to have a validation control whose ControlToValidate is in
fact a hidden control? When I try this I find that the validator
apparently
does not fire. If I make the control Visible="true", then the validator
fires as expected.

I realize that in a sense it doesn't make sense to validate such a
control
since the user can't do anything (directly) to cure the problem. In my
case
however the hidden control contains information representing a bit of
state.
A simplified case would be that I don't want button A to submit until
button
B has already been clicked (and the form submitted.) I "remember" whether
the form has had a "B submit" in a hidden field. I use validation groups
to
differentiate between the two submit buttons.

Any suggestions?

Bill

Mar 5 '06 #3
Elton
On closer examination I find that you are incorrect. In fact the control
*is* rendered; albeit with a munged ID/Name such that the validator can't
see it under the originally specified ID. Use "View Source" to verify
this....

Bill

"Elton W" <El****@discussions.microsoft.com> wrote in message
news:36**********************************@microsof t.com...
Hi Bill,

When you set a control's visible to false on server-side, the control
actually is not rendered to client-side. Hence the validator has nothing
to
validate on client-side.

You should 'hidden' the control on client-side.

Suppose you want to hidden a textbox (ID = txtHidden), using following
code
in Page_Load:

string hiddenTxt = "<script>var txt =
document.getElementById('txtHidden');
txt.style.visibility='hidden';</script>";
Page.RegisterStartupScript("hidden", hiddenTxt);

HTH

Elton Wang

"Bill Cohagan" wrote:
Is it possible to have a validation control whose ControlToValidate is in
fact a hidden control? When I try this I find that the validator
apparently
does not fire. If I make the control Visible="true", then the validator
fires as expected.

I realize that in a sense it doesn't make sense to validate such a
control
since the user can't do anything (directly) to cure the problem. In my
case
however the hidden control contains information representing a bit of
state.
A simplified case would be that I don't want button A to submit until
button
B has already been clicked (and the form submitted.) I "remember" whether
the form has had a "B submit" in a hidden field. I use validation groups
to
differentiate between the two submit buttons.

Any suggestions?

Bill

Mar 5 '06 #4
Hi Bill,

As for the ASP.NET web server controls(include html server controls), if we
set their Visible property to "false", they will not be rendered out so
that Validators on the page can not correctly reference to them. To make
the validator controls be able to validate them and also make them hidden,
I think you can consider use the clientside "display" style of the html
element to hide the control. e.g:

<input type="text" runat="server" id="txtClient" value="2"
style="display:none"/><br />

In such case, the control is hidden on the page, but the validator is still
able to validate it.

Hope this helps.

Regards,

Steven Cheng
Microsoft Online Support

Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)

Mar 6 '06 #5
Steven
This looks like a good solution. Thanks!

Bill

"Steven Cheng[MSFT]" <st*****@online.microsoft.com> wrote in message
news:j4*************@TK2MSFTNGXA03.phx.gbl...
Hi Bill,

As for the ASP.NET web server controls(include html server controls), if
we
set their Visible property to "false", they will not be rendered out so
that Validators on the page can not correctly reference to them. To make
the validator controls be able to validate them and also make them hidden,
I think you can consider use the clientside "display" style of the html
element to hide the control. e.g:

<input type="text" runat="server" id="txtClient" value="2"
style="display:none"/><br />

In such case, the control is hidden on the page, but the validator is
still
able to validate it.

Hope this helps.

Regards,

Steven Cheng
Microsoft Online Support

Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)

Mar 7 '06 #6
Glad that this is of assistance.

If there's anything else we can help, please feel free to post here.

Regards,

Steven Cheng
Microsoft Online Support

Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)

Mar 7 '06 #7

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

Similar topics

6
5771
by: Alex Bink | last post by:
Hi, I have a validating event on a textbox in which I want to prevent the user to leave the textbox without entering the right data. Only if he clicks on another specific control he is allowed...
7
1588
by: ani | last post by:
I have two submit buttons in my form which need to validate two different controls on the page . How do I validate portions of the asp.net page. The two submit buttons should validate their...
2
4869
by: Eran Dvey-Aharon | last post by:
Hi NG! It seems to me that for some reason the validation objects don't know how to work with controls of type 'HiddenField'. It doesn't make any sence - because they are actually rendered as...
0
1543
by: Joe | last post by:
Hi For a while now I have been finding postings of problems with the validating event not firing on controls properly. I too had this problem. The event would fire when clicking on another...
2
2108
by: Chris Dunaway | last post by:
I have a form with a textbox and numerous panels, buttons and other controls. I have handled the textbox Validating and Validated events. The textbox will hold a filename. In the validating...
0
2448
by: Matthew | last post by:
All, I have searched google and the newsgroups but can't find anything the same as what I am experiencing (though I may have missed something). I have controls (textboxes) within UserControls...
0
2423
by: Gary Shell | last post by:
I am experiencing some strange behavior between a UserControl's validating event and a treeview control. Initially, I thought it was related to an issue in the Knowledgebase article 810852...
4
2585
by: suganthy | last post by:
Hi Frnz, I have problem in validating my website,using wc3 validation control, Here the following error i got while debugging my layout.can any one find solution to this problem. # Line 489,...
2
2665
by: Peted | last post by:
Hi if i derive a reference to a control on a winform (ie Control activeControl = somecontrol on the form) how can i test if that control has a validating or validated event and more importantly...
0
7194
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
7267
Oralloy
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,...
1
6976
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
7449
tracyyun
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...
0
5566
agi2029
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,...
1
4993
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...
0
4666
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3148
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
372
bsmnconsultancy
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...

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.