0

I want to get the value of my input tag into my C#.

     <div id="datetimepicker2" class="input-append">
            <input data-format="MM/dd/yyyy HH:mm:ss PP" type="text"></input>
            <span class="add-on">
              <i data-time-icon="icon-time" data-date-icon="icon-calendar">
              </i>
            </span>
    </div>// what should we use here?

The value is set by the user of the page.

4
  • 1
    which control value, you want to get? Commented Sep 30, 2013 at 4:04
  • what do you want to accomplish? Commented Sep 30, 2013 at 4:04
  • what value you are talking about? Commented Sep 30, 2013 at 4:16
  • 1
    The easiest way rather than pulling from form collections values from HTML controls, is to attribute that control with runat="server" and ID="Input1". This makes it then a server control. Then server side it is trivial to get the value: string textValue = this.Input1.Value; Commented Mar 4, 2014 at 18:56

4 Answers 4

7

I did't understand which control value you want to get. But If you want to get input element value into the code behind, you need to set runat="server" attribute, because this is a simple html element not a Asp control.

Add runat="server" and id="your_id" and you should have access to them.

for example:

<input type="text" value="Username" class="input-text autoclear" 
   runat="server" id="myTextBox" />

than you can simply get value of input box like this:

string myStringFromTheInput = myTextBox.Value;

For more options please See here

Sign up to request clarification or add additional context in comments.

Comments

3

Try this

Add name for your input type

 <input data-format="MM/dd/yyyy HH:mm:ss PP" name="txtBox1" type="text"></input>

and try this way for get value in codebehind

string value=Request.Form["txtBox1"];

Comments

0

You can access all your submitted form data at server side by looking into the form Request object.

Ex. Request.Form["txtDate"] OR Request["txtDate"].

Naming the html elements makes easier to look into form collection for specified element.

Comments

-2

If what you posted is your actual code, you have an extra space in your closing tag

</asp: TextBox>

Should be

</asp:TextBox>

and then txt_todata.text should work

1 Comment

The OP want to get input text (html control values not a asp.net control value)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.