473,657 Members | 2,845 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 ControlToValida te 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 1825
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>va r txt = document.getEle mentById('txtHi dden');
txt.style.visib ility='hidden'; </script>";
Page.RegisterSt artupScript("hi dden", hiddenTxt);

HTH

Elton Wang

"Bill Cohagan" wrote:
Is it possible to have a validation control whose ControlToValida te 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****@discuss ions.microsoft. com> wrote in message
news:36******** *************** ***********@mic rosoft.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>va r txt =
document.getEle mentById('txtHi dden');
txt.style.visib ility='hidden'; </script>";
Page.RegisterSt artupScript("hi dden", hiddenTxt);

HTH

Elton Wang

"Bill Cohagan" wrote:
Is it possible to have a validation control whose ControlToValida te 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****@discuss ions.microsoft. com> wrote in message
news:36******** *************** ***********@mic rosoft.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>va r txt =
document.getEle mentById('txtHi dden');
txt.style.visib ility='hidden'; </script>";
Page.RegisterSt artupScript("hi dden", hiddenTxt);

HTH

Elton Wang

"Bill Cohagan" wrote:
Is it possible to have a validation control whose ControlToValida te 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(includ e 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******** *****@TK2MSFTNG XA03.phx.gbl...
Hi Bill,

As for the ASP.NET web server controls(includ e 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
5788
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 to leave the textbox without entering the right information. Is there a way to determine which other control was clicked in the validating event of the textbox? Thanks
7
1593
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 respective controls. If anyone has got any articles or sample pages, please forward.. Thanks..
2
4875
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 <input type=hidden> on the client side, while regular textboxes that rendered almost in the same way know how to be validated. Any idea how to work-around this problem?
0
1549
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 control which had it's causes validation property set to true however if I tabbed on to this control the event wouldn't fire. So after playing around with my code I figured out how to get it to work. I am not sure what the reason behind it is but it...
2
2120
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 event, I check that the string in the textbox is a file that exists or whether or not the string is blank and display a message box in either case. I also call e.Cancel so that the value will be corrected. However, certain buttons on the form...
0
2458
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 which are not behaving as I would expect. Specifically, if there is a command button external to the usercontrol which is activated by a shortcut key (eg Alt-B), the command button Click event handler code 'executes' even though the textbox set...
0
2432
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 (http://support.microsoft.com/kb/810852), but then I realized that the hotfix mentioned was in .Net v1.1, which I am using. I took the sample from that article and recreated the situation I see in my application. (Code included below.) If you run the...
4
2593
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, Column 12: an attribute value specification must be an attribute value literal unless SHORTTAG YES is specified. <input type=hidden name="thx" value="http://mydiscover.bhistg.beta.hodes.com/tha
2
2678
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 how can i tell that those events have finished so that i can test for a new situation. My problem is i am modding some existing code, were the TAB key keypress is captured by a external c# module.
0
8302
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8601
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7314
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6162
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5630
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 then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4150
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4300
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2726
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
1937
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.