Click here to Skip to main content
15,905,414 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi,
I am new to asp and i am implementing a textbox for date using below input type
HTML
<input name="Txtdoa" type="date"  value="Date Of Arrival" id="Txtdoa" title="Date Of Arrival" class="water" style="width:100%;">


Can anyone tell me how to retrieve value from this input textbox display onto asp label using c#.Thank you in advance god bless you
Posted
Updated 30-Aug-17 7:46am
v3

In ASP.NET you don't have a TextBox control you have an input field instead. You can get its properties or values on the serverside (code behind) using the Request class of ASP.NET.

First you need to make sure, that the input field you're trying to access is a part of a form. Since only forms invoke submit method inside the HTML elements. Here is an example of such HTML code

HTML
<!-- method="post" is totally unrelated, don't fall for it -->
<form method="post">
  <input name="Txtdoa" type="date"  value="Date Of Arrival" id="Txtdoa" title="Date Of Arrival" class="water" style="width:100%;">
  <input type="submit" value="Submit" />
</form>


The above form has an input field (to get the date) and a submit button. Once submitted the form will be passed on to the server, with the input fields specified inside it. In this case, the input field for the date will be sent. Youc an get the value on the serverside, using the name of the field. Like this

C#
// get the value of the object with name Txtdoa in the Request
var date = Request["Txtdoa"];
// use date variable inside the code where required. 


This is the example code, you can learn more of this stuff at ASP.NET official website. http://asp.net/web-pages[^]. They've got a lot of cool codes for you to get started.
 
Share this answer
 
Comments
faizel s 5-Oct-14 12:43pm    
here i tried like this in code behind but it is'nt displaying value to label
Label4.Text = Request["Txtdoa"];
Afzaal Ahmad Zeeshan 5-Oct-14 12:48pm    
Then try this one,
Label4.Text = Txtdoa.Text
faizel s 5-Oct-14 12:56pm    
Still not working
Afzaal Ahmad Zeeshan 5-Oct-14 12:57pm    
Which technology are you using? Web Pages? MVC? Web Forms?
faizel s 5-Oct-14 13:03pm    
web pages
asp.net version 4
first, any control you wish to access server side must include a runat="server" tag

2nd -
string getTextValues = Page.Request.Form["text1"].ToString();
 
Share this answer
 
Comments
Afzaal Ahmad Zeeshan 6-Oct-14 4:48am    
That will never help him out, runat="server" isn't available in Web Pages.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900