HiddenFields access

T

tshad

I have a couple of HiddenField controls on my page:

<asp:HiddenField ID="MaxDropDate" runat="server" />
<asp:HiddenField ID="MinDropDate" runat="server" />

But when I try to access them:

maxDropDate = MaxDropDate.Value;
minDropDate = MinDropDate.Value;

I get an error:

The name 'MaxDropDate' doesnt' exist in the current context.

Why is that?

They are there.

Thanks,

Tom
 
N

Nathan Sokalski

Try looking at the *.aspx.designer.cs file and make sure that it is declared
there. Even though this file is supposed to be automatically generated,
sometimes it doesn't get regenerated every time you add a control. also,
even though I can see that you have different capitalization for maxDropDate
and MaxDropDate, it is considered very bad practice to use the same spelling
for two variables, controls, or other types of objects, because it can be
very easy to mistype the capitalization while writing code. We may also be
able to help you more if you show us some of the other code on the page.
Hopefully this helps.
 
S

Scott M.

Are you sure that these controls are declared within the page's main <form>
tag?

-Scott
 
G

Gregory A. Beamer

I have a couple of HiddenField controls on my page:

<asp:HiddenField ID="MaxDropDate" runat="server" />
<asp:HiddenField ID="MinDropDate" runat="server" />

But when I try to access them:

maxDropDate = MaxDropDate.Value;
minDropDate = MinDropDate.Value;

I get an error:

The name 'MaxDropDate' doesnt' exist in the current context.

Why is that?

They are there.

They may not be properly declared in the code behind (designer file in
ASP.NET 4.0).

I would also make sure they actually have a value in your testing.

Peace and Grace,
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,537
Members
45,021
Latest member
AkilahJaim

Latest Threads

Top