HiddenFields access

Discussion in 'ASP .Net' started by tshad, Oct 1, 2009.

  1. tshad

    tshad Guest

    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
    tshad, Oct 1, 2009
    #1
    1. Advertising

  2. 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.
    --
    Nathan Sokalski

    http://www.nathansokalski.com/

    "tshad" <> wrote in message
    news:...
    >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
    >
    Nathan Sokalski, Oct 1, 2009
    #2
    1. Advertising

  3. tshad

    Scott M. Guest

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

    -Scott

    "tshad" <> wrote in message
    news:...
    >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
    >
    Scott M., Oct 1, 2009
    #3
  4. "tshad" <> wrote in news:ups4lWiQKHA.764
    @TK2MSFTNGP02.phx.gbl:

    > 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! |
    *******************************************
    Gregory A. Beamer, Oct 1, 2009
    #4
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. luican
    Replies:
    3
    Views:
    12,235
    Aaron W. West
    Jun 4, 2004
  2. david
    Replies:
    2
    Views:
    1,612
    Ken Cox [Microsoft MVP]
    Nov 24, 2003
  3. Guest
    Replies:
    2
    Views:
    532
    Guest
    Feb 2, 2004
  4. Guest
    Replies:
    0
    Views:
    495
    Guest
    Feb 9, 2004
  5. MSDN
    Replies:
    0
    Views:
    664
Loading...

Share This Page