HiddenFields access

  • Thread starter Thread starter tshad
  • Start date Start date
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
 
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.
 
Are you sure that these controls are declared within the page's main <form>
tag?

-Scott
 
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,


--
Gregory A. Beamer
MVP; MCP: +I, SE, SD, DBA

Twitter: @gbworld
Blog: http://gregorybeamer.spaces.live.com

*******************************************
| Think outside the box! |
*******************************************
 
Back
Top