我试图在VB ASP.NET中的“休息”按钮重置TextBox中的用户输入,我的代码在这里-
<body>
<form id="form1" runat="server">
<div>
<asp:Label ID="Label1" runat="server" Text="Label">Input text:</asp:Label><br />
<asp:TextBox ID="TextBox1" runat="server" ToolTip="Enter your name here!" AutoCompleteType="Disabled"></asp:TextBox><br />
<asp:Label ID="Label4" runat="server" Text="Label">Output text:</asp:Label><br />
<asp:TextBox ID="TextBox2" runat="server"></asp:TextBox><br />
<asp:Button ID="Button1" runat="server" Text="Button" />
<asp:Button ID="Button2" runat="server" BackColor="#0066FF" Text="Reset" />
<br />
</div>
</form>
</body>
VB代码是
Public Class WebForm1
Inherits System.Web.UI.Page
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
TextBox1.Attributes.Add("AutoCompleteType", "off")
TextBox1.Focus()
'If Not IsPostBack Then
'TextBox1.Text = "Enter your name here!"
'End If
End Sub
Protected Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
Dim MyString As String = TextBox1.Text
'Response.Write(MyString)
TextBox2.Text = MyString
End Sub
Protected Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click
TextBox2.Clear()
TextBox1.Clear()
End Sub
End Class
错误是:
“清除”不是“ System.Web.UI.WebControls.TextBox”的成员 “清除”不是“ System.Web.UI.WebControls.TextBox”的成员
答案 0 :(得分:2)
TextBox
不包含方法Clear
。
您可以通过为属性Text
分配一个空字符串值来清除其内容,如下所示。
TextBox2.Text = "";
TextBox1.Text = "";