473,899 Members | 4,299 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

RequiredFieldVa lidator for Hidden Input?

WB
Hi,

I need to validate a hidden input in my webform to ensure that it's got
value. The controls look something like this:
<input id="HidSelected States" type="hidden" runat="server" /><br /><br />
<asp:Button ID="BtnSubmit" runat="server" OnClick="BtnSub mit_Click"
Text="Submit" ValidationGroup ="submitStat es" />
<asp:RequiredFi eldValidator ID="RequiredFie ldValidator1"
ControlToValida te="HidSelected States" runat="server" ErrorMessage="P lease
select the states" ValidationGroup ="submitStat es" />
However, this gives the following error

System.Web.Http Exception: Control 'HidSelectedSta tes' referenced by the
ControlToValida te property of 'RequiredFieldV alidator1' cannot be validated

How can I get around this?

WB.
Mar 13 '06 #1
4 11727
I don't think the Validator Controls are capable of validating hidden input
fields. The reason for this is that

1. <input type="hidden"> does not have a corresponding class in the
System.Web.UI.W ebControls namespace
2. Because the value attribute can only be modified using code, the value
should be validated before it is assigned to the tag, therefore there is no
need for a validator other than server-side code if the value needs compared
against something the client does not have access to, such as a database

What is your reason for needing a validator for the hidden field? It sounds
like you are just keeping track of what states the user has selected. I
would select doing this using a multiple-selection ListBox like the
following:

<asp:ListBox id="HidSelected States" runat="server"
SelectionMode=" Multiple"></asp:ListBox>

If you want more suggestions, let me know in more detail what you are doing
with the hidden input. Good Luck!
--
Nathan Sokalski
nj********@hotm ail.com
http://www.nathansokalski.com/

"WB" <WB@discussions .microsoft.com> wrote in message
news:A4******** *************** ***********@mic rosoft.com...
Hi,

I need to validate a hidden input in my webform to ensure that it's got
value. The controls look something like this:
<input id="HidSelected States" type="hidden" runat="server" /><br /><br />
<asp:Button ID="BtnSubmit" runat="server" OnClick="BtnSub mit_Click"
Text="Submit" ValidationGroup ="submitStat es" />
<asp:RequiredFi eldValidator ID="RequiredFie ldValidator1"
ControlToValida te="HidSelected States" runat="server" ErrorMessage="P lease
select the states" ValidationGroup ="submitStat es" />
However, this gives the following error

System.Web.Http Exception: Control 'HidSelectedSta tes' referenced by the
ControlToValida te property of 'RequiredFieldV alidator1' cannot be
validated

How can I get around this?

WB.

Mar 14 '06 #2
WB
Hi Nathan,

Thanks for the reply.

Actually the reason I'm using a hidden control is that I have a treeview
with checkboxes of states (eg. California, Oregon etc) for users to select.
This treeview is built by a 3rd party software and the checkboxes are not
server control. So I have a client script to copy the selected boxes value to
the hidden field so that I can use the value on PostBack.

A ListBox won't do 'cuz I need to show the hierachy of countries > states.

Any suggestions?
WB.
"Nathan Sokalski" wrote:
I don't think the Validator Controls are capable of validating hidden input
fields. The reason for this is that

1. <input type="hidden"> does not have a corresponding class in the
System.Web.UI.W ebControls namespace
2. Because the value attribute can only be modified using code, the value
should be validated before it is assigned to the tag, therefore there is no
need for a validator other than server-side code if the value needs compared
against something the client does not have access to, such as a database

What is your reason for needing a validator for the hidden field? It sounds
like you are just keeping track of what states the user has selected. I
would select doing this using a multiple-selection ListBox like the
following:

<asp:ListBox id="HidSelected States" runat="server"
SelectionMode=" Multiple"></asp:ListBox>

If you want more suggestions, let me know in more detail what you are doing
with the hidden input. Good Luck!
--
Nathan Sokalski
nj********@hotm ail.com
http://www.nathansokalski.com/

"WB" <WB@discussions .microsoft.com> wrote in message
news:A4******** *************** ***********@mic rosoft.com...
Hi,

I need to validate a hidden input in my webform to ensure that it's got
value. The controls look something like this:
<input id="HidSelected States" type="hidden" runat="server" /><br /><br />
<asp:Button ID="BtnSubmit" runat="server" OnClick="BtnSub mit_Click"
Text="Submit" ValidationGroup ="submitStat es" />
<asp:RequiredFi eldValidator ID="RequiredFie ldValidator1"
ControlToValida te="HidSelected States" runat="server" ErrorMessage="P lease
select the states" ValidationGroup ="submitStat es" />
However, this gives the following error

System.Web.Http Exception: Control 'HidSelectedSta tes' referenced by the
ControlToValida te property of 'RequiredFieldV alidator1' cannot be
validated

How can I get around this?

WB.


Mar 14 '06 #3
Well, if the control is from a 3rd party, I think you're stuck with either
writing client-side JavaScript to validate it or validating it server-side.
An idea for validating it client-side would be to save in a global variable
what you were trying to save as the hidden field's value. Then add an
onSubmit event that validates and, if it is valid, appends this variable's
value to the URL as a querystring. This will allow you to submit it as if it
were part of the form. It might require a little extra code, but it's the
best I can come up with for a control that you can only access with
JavaScript.
--
Nathan Sokalski
nj********@hotm ail.com
http://www.nathansokalski.com/

"WB" <WB@discussions .microsoft.com> wrote in message
news:F6******** *************** ***********@mic rosoft.com...
Hi Nathan,

Thanks for the reply.

Actually the reason I'm using a hidden control is that I have a treeview
with checkboxes of states (eg. California, Oregon etc) for users to
select.
This treeview is built by a 3rd party software and the checkboxes are not
server control. So I have a client script to copy the selected boxes value
to
the hidden field so that I can use the value on PostBack.

A ListBox won't do 'cuz I need to show the hierachy of countries > states.

Any suggestions?
WB.
"Nathan Sokalski" wrote:
I don't think the Validator Controls are capable of validating hidden
input
fields. The reason for this is that

1. <input type="hidden"> does not have a corresponding class in the
System.Web.UI.W ebControls namespace
2. Because the value attribute can only be modified using code, the value
should be validated before it is assigned to the tag, therefore there is
no
need for a validator other than server-side code if the value needs
compared
against something the client does not have access to, such as a database

What is your reason for needing a validator for the hidden field? It
sounds
like you are just keeping track of what states the user has selected. I
would select doing this using a multiple-selection ListBox like the
following:

<asp:ListBox id="HidSelected States" runat="server"
SelectionMode=" Multiple"></asp:ListBox>

If you want more suggestions, let me know in more detail what you are
doing
with the hidden input. Good Luck!
--
Nathan Sokalski
nj********@hotm ail.com
http://www.nathansokalski.com/

"WB" <WB@discussions .microsoft.com> wrote in message
news:A4******** *************** ***********@mic rosoft.com...
> Hi,
>
> I need to validate a hidden input in my webform to ensure that it's got
> value. The controls look something like this:
>
>
> <input id="HidSelected States" type="hidden" runat="server" /><br /><br
> />
> <asp:Button ID="BtnSubmit" runat="server" OnClick="BtnSub mit_Click"
> Text="Submit" ValidationGroup ="submitStat es" />
> <asp:RequiredFi eldValidator ID="RequiredFie ldValidator1"
> ControlToValida te="HidSelected States" runat="server"
> ErrorMessage="P lease
> select the states" ValidationGroup ="submitStat es" />
>
>
> However, this gives the following error
>
> System.Web.Http Exception: Control 'HidSelectedSta tes' referenced by the
> ControlToValida te property of 'RequiredFieldV alidator1' cannot be
> validated
>
> How can I get around this?
>
> WB.


Mar 14 '06 #4
WB
Hi,

Thanks for the advice.

I've decided to just user a label control like this:
<asp:Label ID="NoStateSele cted" runat="server" CssClass="error " Text="Please
select states" Visible="False" />

And if no state is selected (ie. empty hidden field), I will turn this
lablel's visible attribute to true and won't process the form...
WB.
"Nathan Sokalski" wrote:
Well, if the control is from a 3rd party, I think you're stuck with either
writing client-side JavaScript to validate it or validating it server-side.
An idea for validating it client-side would be to save in a global variable
what you were trying to save as the hidden field's value. Then add an
onSubmit event that validates and, if it is valid, appends this variable's
value to the URL as a querystring. This will allow you to submit it as if it
were part of the form. It might require a little extra code, but it's the
best I can come up with for a control that you can only access with
JavaScript.
--
Nathan Sokalski
nj********@hotm ail.com
http://www.nathansokalski.com/

"WB" <WB@discussions .microsoft.com> wrote in message
news:F6******** *************** ***********@mic rosoft.com...
Hi Nathan,

Thanks for the reply.

Actually the reason I'm using a hidden control is that I have a treeview
with checkboxes of states (eg. California, Oregon etc) for users to
select.
This treeview is built by a 3rd party software and the checkboxes are not
server control. So I have a client script to copy the selected boxes value
to
the hidden field so that I can use the value on PostBack.

A ListBox won't do 'cuz I need to show the hierachy of countries > states.

Any suggestions?
WB.
"Nathan Sokalski" wrote:
I don't think the Validator Controls are capable of validating hidden
input
fields. The reason for this is that

1. <input type="hidden"> does not have a corresponding class in the
System.Web.UI.W ebControls namespace
2. Because the value attribute can only be modified using code, the value
should be validated before it is assigned to the tag, therefore there is
no
need for a validator other than server-side code if the value needs
compared
against something the client does not have access to, such as a database

What is your reason for needing a validator for the hidden field? It
sounds
like you are just keeping track of what states the user has selected. I
would select doing this using a multiple-selection ListBox like the
following:

<asp:ListBox id="HidSelected States" runat="server"
SelectionMode=" Multiple"></asp:ListBox>

If you want more suggestions, let me know in more detail what you are
doing
with the hidden input. Good Luck!
--
Nathan Sokalski
nj********@hotm ail.com
http://www.nathansokalski.com/

"WB" <WB@discussions .microsoft.com> wrote in message
news:A4******** *************** ***********@mic rosoft.com...
> Hi,
>
> I need to validate a hidden input in my webform to ensure that it's got
> value. The controls look something like this:
>
>
> <input id="HidSelected States" type="hidden" runat="server" /><br /><br
> />
> <asp:Button ID="BtnSubmit" runat="server" OnClick="BtnSub mit_Click"
> Text="Submit" ValidationGroup ="submitStat es" />
> <asp:RequiredFi eldValidator ID="RequiredFie ldValidator1"
> ControlToValida te="HidSelected States" runat="server"
> ErrorMessage="P lease
> select the states" ValidationGroup ="submitStat es" />
>
>
> However, this gives the following error
>
> System.Web.Http Exception: Control 'HidSelectedSta tes' referenced by the
> ControlToValida te property of 'RequiredFieldV alidator1' cannot be
> validated
>
> How can I get around this?
>
> WB.


Mar 14 '06 #5

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

Similar topics

10
3715
by: Randell D. | last post by:
Folks, Perhaps someone can figure this out - this is 'the process of my script' I have a form whereby I can add multiple contacts to a single address. There is only one firstname/lastname/telephone box - when the user clicks the add button, I read the values from the form fields and record them into a hidden text input field. This part works because during debugging, I have converted the <input type=hidden> into a <input type=text>...
6
2165
by: BK | last post by:
I'm having a really strange problem with and HtmlSelect server control (listbox) and a RequiredFieldValidator that I am trying to use to make sure that someone has items in the listbox. The way that the HtmlSelect is populated is via a combination of client-side javascript and another aspx page (launched by the javascript). Anyway, everything seems to work just fine in terms of populating the HtmlSelect. However, when I postback the...
1
328
by: peshrad | last post by:
Hi ! I'm using Visual Studio .NET to program a Web application coding in C#. In my form I use an HtmlSelect control that calls a JavaScript function when the selected item changes. This JavaScript function calls the submit() method of the form. For this HtmlSelect control I have also programmed the ServerChange event, which is able to dynamically set up the form.
2
2239
by: buran | last post by:
Dear ASP.NET Programmers, I am using a CompareValidator control to check the values entered into a texbox. The textbox is for currencies, so the property Operator is set to DataTypeCheck and the Type property is set to Currency. However, I would like to control check whether the user enters a value or not. Do I have to add an RequiredFieldValidator? Can't CompareValidator handle this? Thanks in advance, Burak
7
8994
by: Ed West | last post by:
Hello, I have a simple form with some input boxes. After validation if one fails, then I would like to at the top of the page say something like "The following fields in red are required" and then change the label in front of the textbox or dropdown list to red... is this possible with asp.net? It seems you can only put a RequiredFieldValidator on the page, and if it fails validation then that text is displayed... ? Thanks
2
1409
by: Dave | last post by:
Hello. I have the web form where user can input some data in textboxes, I'm validating user input with RequiredFieldValidator controls, then I have two buttons "OK" and "Cancel". Now when I press "OK" the RequiredFieldValidator works fine, but when I press "Cancel" I don't want to validate inputs. So how can I temporarily disable RequiredFieldValidator, because I want press "Cancel" and handle some actions at server side?
2
2103
by: Hongbo | last post by:
Hi, I have a Asp.Net written in C#. It serve as information input form. The form encounters sort of random problem with the email field and state field. I have validator attached with these 2 fields as the following: ===== <form id="creditcardform" method="post" runat="server"> Email: <asp:textbox id="txtBillEmail" maxlength="50" width="200" runat="server" /> <asp:requiredfieldvalidator id="vp10" runat="server" initialvalue="" ...
1
6003
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 the .ControlToValidate property. When a new Item is created, I check the information coming in from my database. Based on a field value (TypeID), I create a different control needed for input: (TextBox, ListBox, DropdownList, etc...), add this...
6
2087
by: dba | last post by:
using the following code with a problem.... echo "<input type='hidden' name='member_id' value=\"{$row}\">{$row}"; echo "<input type='radio' name='member_name' value=\"{$row}\">{$row}<br />"; The post_data.php program posts the following member id is: 0009
0
9997
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, weíll explore What is ONU, What Is Router, ONU & Routerís main usage, and What is the difference between ONU and Router. Letís take a closer look ! Part I. Meaning of...
0
9845
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
10866
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10976
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10497
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
6082
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4721
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
4301
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
3320
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 can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.