473,387 Members | 1,541 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

RequiredFieldValidator 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="HidSelectedStates" type="hidden" runat="server" /><br /><br />
<asp:Button ID="BtnSubmit" runat="server" OnClick="BtnSubmit_Click"
Text="Submit" ValidationGroup="submitStates" />
<asp:RequiredFieldValidator ID="RequiredFieldValidator1"
ControlToValidate="HidSelectedStates" runat="server" ErrorMessage="Please
select the states" ValidationGroup="submitStates" />
However, this gives the following error

System.Web.HttpException: Control 'HidSelectedStates' referenced by the
ControlToValidate property of 'RequiredFieldValidator1' cannot be validated

How can I get around this?

WB.
Mar 13 '06 #1
4 11673
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.WebControls 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="HidSelectedStates" 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********@hotmail.com
http://www.nathansokalski.com/

"WB" <WB@discussions.microsoft.com> wrote in message
news:A4**********************************@microsof t.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="HidSelectedStates" type="hidden" runat="server" /><br /><br />
<asp:Button ID="BtnSubmit" runat="server" OnClick="BtnSubmit_Click"
Text="Submit" ValidationGroup="submitStates" />
<asp:RequiredFieldValidator ID="RequiredFieldValidator1"
ControlToValidate="HidSelectedStates" runat="server" ErrorMessage="Please
select the states" ValidationGroup="submitStates" />
However, this gives the following error

System.Web.HttpException: Control 'HidSelectedStates' referenced by the
ControlToValidate property of 'RequiredFieldValidator1' 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.WebControls 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="HidSelectedStates" 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********@hotmail.com
http://www.nathansokalski.com/

"WB" <WB@discussions.microsoft.com> wrote in message
news:A4**********************************@microsof t.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="HidSelectedStates" type="hidden" runat="server" /><br /><br />
<asp:Button ID="BtnSubmit" runat="server" OnClick="BtnSubmit_Click"
Text="Submit" ValidationGroup="submitStates" />
<asp:RequiredFieldValidator ID="RequiredFieldValidator1"
ControlToValidate="HidSelectedStates" runat="server" ErrorMessage="Please
select the states" ValidationGroup="submitStates" />
However, this gives the following error

System.Web.HttpException: Control 'HidSelectedStates' referenced by the
ControlToValidate property of 'RequiredFieldValidator1' 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********@hotmail.com
http://www.nathansokalski.com/

"WB" <WB@discussions.microsoft.com> wrote in message
news:F6**********************************@microsof t.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.WebControls 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="HidSelectedStates" 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********@hotmail.com
http://www.nathansokalski.com/

"WB" <WB@discussions.microsoft.com> wrote in message
news:A4**********************************@microsof t.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="HidSelectedStates" type="hidden" runat="server" /><br /><br
> />
> <asp:Button ID="BtnSubmit" runat="server" OnClick="BtnSubmit_Click"
> Text="Submit" ValidationGroup="submitStates" />
> <asp:RequiredFieldValidator ID="RequiredFieldValidator1"
> ControlToValidate="HidSelectedStates" runat="server"
> ErrorMessage="Please
> select the states" ValidationGroup="submitStates" />
>
>
> However, this gives the following error
>
> System.Web.HttpException: Control 'HidSelectedStates' referenced by the
> ControlToValidate property of 'RequiredFieldValidator1' 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="NoStateSelected" 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********@hotmail.com
http://www.nathansokalski.com/

"WB" <WB@discussions.microsoft.com> wrote in message
news:F6**********************************@microsof t.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.WebControls 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="HidSelectedStates" 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********@hotmail.com
http://www.nathansokalski.com/

"WB" <WB@discussions.microsoft.com> wrote in message
news:A4**********************************@microsof t.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="HidSelectedStates" type="hidden" runat="server" /><br /><br
> />
> <asp:Button ID="BtnSubmit" runat="server" OnClick="BtnSubmit_Click"
> Text="Submit" ValidationGroup="submitStates" />
> <asp:RequiredFieldValidator ID="RequiredFieldValidator1"
> ControlToValidate="HidSelectedStates" runat="server"
> ErrorMessage="Please
> select the states" ValidationGroup="submitStates" />
>
>
> However, this gives the following error
>
> System.Web.HttpException: Control 'HidSelectedStates' referenced by the
> ControlToValidate property of 'RequiredFieldValidator1' 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
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...
6
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...
1
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...
2
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...
7
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...
2
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...
2
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...
1
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...
6
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 />"; ...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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
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,...

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.