accessing html fields

Discussion in 'ASP .Net Web Services' started by Jessica Weiner, Jul 5, 2006.

  1. I have an input field defined outside the <form> area. Its a simple html
    text input that is used to enter the number of hours.

    <input id="HoursField" name="hours" type="text" />

    I want to access this field from the server side (c# code). I tried these
    two methods to access the field but they dont work. Please help.

    String[] tempArray;
    tempArray = Request.Form.GetValues("hours");
    Response.Write (tempArray[0]);

    ---

    string val = Request.QueryString["hours"].ToString();
    Response.Write (val);


    Jessica
     
    Jessica Weiner, Jul 5, 2006
    #1
    1. Advertising

  2. Jessica Weiner

    Scott M. Guest

    All form fields MUST be within the <FORM> element, otherwise their
    name/value pair are not posted to the server when the form submits.

    Also, if you only have one element named "hours" and it is a textbox, it
    will not return an array, it will just return one value.

    This code will do it:

    String hoursValue;
    hoursValue = Request.Form("hours");
    Response.Write (hoursValue);

    Or, you could define the input like this:

    <input id="HoursField" name="hours" type="text" runat="server" />

    and your server code would simply be:

    String hoursValue;
    hoursValue = HoursField.Text;
    Response.Write (hoursValue);



    "Jessica Weiner" <> wrote in message
    news:AWCqg.126762$...
    >I have an input field defined outside the <form> area. Its a simple html
    >text input that is used to enter the number of hours.
    >
    > <input id="HoursField" name="hours" type="text" />
    >
    > I want to access this field from the server side (c# code). I tried these
    > two methods to access the field but they dont work. Please help.
    >
    > String[] tempArray;
    > tempArray = Request.Form.GetValues("hours");
    > Response.Write (tempArray[0]);
    >
    > ---
    >
    > string val = Request.QueryString["hours"].ToString();
    > Response.Write (val);
    >
    >
    > Jessica
    >
     
    Scott M., Jul 5, 2006
    #2
    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. call_me_anything
    Replies:
    4
    Views:
    502
    Pete Becker
    Sep 30, 2007
  2. Cyril.Liu
    Replies:
    0
    Views:
    479
    Cyril.Liu
    Dec 2, 2008
  3. Jessica Weiner

    accessing html fields

    Jessica Weiner, Jul 5, 2006, in forum: ASP .Net Building Controls
    Replies:
    1
    Views:
    128
    ValliM
    Jul 5, 2006
  4. middletree

    how to copy from fields to other fields

    middletree, Nov 5, 2003, in forum: ASP General
    Replies:
    1
    Views:
    186
    middletree
    Nov 5, 2003
  5. Jessica Weiner

    accessing html input fields

    Jessica Weiner, Jul 5, 2006, in forum: Javascript
    Replies:
    2
    Views:
    113
    marss
    Jul 5, 2006
Loading...

Share This Page