将文本框值分配给字符串

时间:2012-02-01 09:34:32

标签: asp.net vb.net

 Dim loc As String = ""
    If txtlocated.Value <> "ABC" Then
        loc = txtlocated.Value

txtlocated是HTML文本框的ID。我想将文本框的值分配给字符串loc。当我调试它时,loc显示为null,文本框值不会传递给字符串。任何建议代码中的错误。

谢谢,

4 个答案:

答案 0 :(得分:1)

尝试将其更改为:

Dim loc As String = ""
If txtlocated.Text <> "ABC" Then
    loc = txtlocated.Text
End If

注意我使用的是Text,而不是Value

答案 1 :(得分:0)

不确定,但试一试:

loc=string.Format("{0}",Request.Form["txtlocated"]);

答案 2 :(得分:0)

我不知道VB(我是C#家伙)。但是HtmlControls要求你使用Form.Request

在C#中

string loc = Form.Request["controlid"];

答案 3 :(得分:0)

尝试

Dim text As String = Request("txtlocated")

Dim loc As String = "" 
If text <> "ABC" Then
     loc = text 
End If 
相关问题