如何使用c#从输入类型=日期文本框中检索值 [英] how to retrieve value from input type=date textbox using c#

查看:104
本文介绍了如何使用c#从输入类型=日期文本框中检索值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



我是asp新手,我正在使用以下输入类型实现日期文本框

Hi,
I am new to asp and i am implementing a textbox for date using below input type

<input name="Txtdoa" type="date"  value="Date Of Arrival" id="Txtdoa" title="Date Of Arrival" class="water" style="width:100%;">





任何人都可以告诉我如何使用c#从这个输入文本框显示中检索值到asp标签。谢谢你提前上帝保佑你



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

推荐答案

在ASP.NET中,你没有TextBox控件,而是有一个输入字段。您可以使用ASP.NET的 Request 类在服务器端(代码隐藏)上获取其属性或值。



首先,您需要确保您尝试访问的输入字段是表单的一部分。由于只有表单在HTML元素内调用 submit 方法。以下是此类HTML代码的示例



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

<!-- 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

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





这是示例代码,您可以在ASP.NET官方网站上了解更多这方面的内容。 http://asp.net/web-pages [ ^ ]。他们有很多很酷的代码供您开始使用。



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.


首先,您希望访问服务器端的任何控件都必须包含runat =server标签



2nd -
first, any control you wish to access server side must include a runat="server" tag

2nd -
string getTextValues = Page.Request.Form["text1"].ToString();


这篇关于如何使用c#从输入类型=日期文本框中检索值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆