1

I am trying to clear the value of the html textbox in vb.net using the provided button by vb.net.

Can someone please help me?

The frontend code for html textbox:

<input type="text" name="Desc" id="desc" size="28" maxlength="50" value=''>

Button code:

Protected Sub Button2_Click(ByVal sender As Object, ByVal e As EventArgs) Handles Button2.Click
     desc.Text = "" 
     ' What code should I do here?
End Sub
djquest
  • 31
  • 9
  • add `runat="server"` to the HTML input, then you can access it by the ID and clear it with `desc.Clear()` – Cory Jul 29 '15 at 03:25

2 Answers2

0

I think TextBox1.Text = "" should be working, but try TextBox1.Clear() to clear the contents of the text box and allow re-entry. You also need to add runat="server" in your HTML input.

mafap
  • 371
  • 3
  • 18
  • 40
  • 'Text' is not a member of 'System.Web.UI.HtmlControls.HtmlInputText'. so `TextBox1.Text = String.Empty` wont work –  Jul 29 '15 at 03:39
0

To get access of HTML control in the back-End you have to give runat="server". you can refer this thread for more information about runat="server". Hence your input tag will be like the following:

  <input runat="server" type="text" name="Desc" id="desc" size="28" maxlength="50" value="sample">

There is no Text property for HTML controls, so you have to use

desc.Value =""

for Clear/Reset the value of the control

Community
  • 1
  • 1