vb.net 在VB代码中获取输入类型文本的值

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/21187344/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-17 16:28:35  来源:igfitidea点击:

Get value of Input type text in VB Code

htmlasp.netvb.net

提问by HelpASisterOut

I have this control in ASP:

我在 ASP 中有这个控件:

   <input type="text"  id="datepicker" name="datepicker" runat="server">

There's a JQuery function related to it

有一个与之相关的 JQuery 函数

I want to get the value in the input text in my VB code,so I used this

我想在我的 VB 代码中获取输入文本的值所以我使用了这个

 Dim VALUE As String
 VALUE = Request.Form("datepicker")
 Dim VALUE As String
 VALUE = Request.Form("datepicker")

But it's not working.

但它不起作用。

I am getting VALUE is nothing

我得到的价值是什么

What am I doing wrong?

我究竟做错了什么?

采纳答案by RemarkLima

You need to get the TextBox object in your code behind - because it has a runat="server"tag the code can see it:

你需要在你的代码后面获取 TextBox 对象 - 因为它有一个runat="server"代码可以看到它的标签:

Dim VALUE As String
VALUE = datepicker.text

EDIT

编辑

Apologies, just saw you're using a HTML <input />, rather than a <asp:TextBox />control. However, the runat="server"should mean your codebehind can still access the object but the .textmay not be available... You may need .valueor .ToString

抱歉,刚刚看到您使用的是 HTML <input />,而不是<asp:TextBox />控件。但是,这runat="server"应该意味着您的代码隐藏仍然可以访问该对象,但.text可能不可用......您可能需要.value.ToString

回答by nestedloop

Try:

尝试:

VALUE = Request.Form("datepicker")(0)

because Request.Formis a Collection.

因为Request.Form是一个集合。

Also, because of the runat="server" part, your input is visible server side, so this works too:

此外,由于 runat="server" 部分,您的输入是可见的服务器端,所以这也适用:

VALUE = datepicker.Value

回答by ekad

Since datepickerhas runat="server"property, you can get the value this way:

由于datepicker具有runat="server"属性,您可以通过以下方式获取值:

 Dim VALUE As String
 VALUE = datepicker.Value