Accessing input fields declared outside the form

Discussion in 'ASP .Net' 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. Advertisements

  2. Jessica Weiner

    neilmcguigan Guest

    1. some people consider it bad form to post to more than one newgroup
    :)

    2. why is this input field outside of the form?

    cheers

    neil
     
    neilmcguigan, Jul 5, 2006
    #2
    1. Advertisements

  3. Jessica Weiner

    nasirmajor Guest

    don't declare it outside the form tag.
    use
    <input id="hoursfield" name="hours" type="text" runat="server">

    and then use it in script tags
    like
    string hours="";
    hours=hoursfield.text;
     
    nasirmajor, Jul 5, 2006
    #3
    1. Advertisements

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 (here). After that, you can post your question and our members will help you out.