user123456789
user123456789

Reputation: 2004

how to clear text box when first opened

I have a search function list with a text box on top. The user can enter letters into the text box and the list will get updated after each letter.

For example the user enters "A", then the list will only show trailers containing "A".

The problem I am having is the text box isn't clearing when the user closes the search. When I open up the search again, whatever I entered is still there. I don't know how it is remembering what I entered but how to I clear the text box each time the search is opened?

<tr>
    <td class="Header">
        Trailer Type
        <a style="float:right;width:16px;height:16px;margin-right:0px;" title="Pick from list..." class="iconSearch" id="btnShowType"></a>                                            
    </td>
    <td></td>
    <td>
        <asp:HiddenField ID="hfTrailerTypeID" Value="0" runat="server" />
        <asp:TextBox runat="server" ID="txtTrailerType"></asp:TextBox>
    </td>
</tr>

Upvotes: 0

Views: 1931

Answers (6)

sadia zar
sadia zar

Reputation: 62

protected void Page_Load(object sender, EventArgs e){
if (!IsPostBack)
        {
           txtTrailerType.Text="";
        }
}

Upvotes: 0

sadia zar
sadia zar

Reputation: 62

protected void Page_Load(object sender, EventArgs e){ if (!IsPostBack) { txtTrailerType.Text=""; } }

May be it helps..

Upvotes: 0

Vishal
Vishal

Reputation: 127

Closing the search, seems like you are hiding the search panel(can be a 'div'). That definitely would not clear the fields. For that, you need to either clear it manually when user clicks close button or if you are refreshing page, then on page load.

Here are the solutions to clear it up by jQuery.

  1. One of the easy solution is:

    $( "form" )[ 0 ].reset();

  2. But if you want to clear inputs fields within an element, you can do this:

    $.fn.cleanUpControls = function() { return this.each(function() { var type = this.type, tag = this.tagName.toLowerCase(); if (tag == 'form') return $(':input',this).clearForm(); if (type == 'text' || type == 'password' || tag == 'textarea') this.value = ''; }); };

    $('div.searchPanel').cleanUpControls();
    

Upvotes: 0

Thomas Koelle
Thomas Koelle

Reputation: 3752

It is a feature of .Net. If you had a pure html it would achieve what you want

<input type="text" id="txtTrailerType" />

Else just clear it in the round-trip e.g. on Page_Load

txtTrailerType.Text = "";

Upvotes: 0

Dot_NET Pro
Dot_NET Pro

Reputation: 2123

Proposed Solution 1:

In the provider portal, need to set AutoCompleteType=Disabled property for all text boxes where user enters the sensitive information

Disadvantage: This solution may not work in FireFox. Need to test in FireFox and confirm.

Solution 2:

This solution works in all browsers.

<asp:TextBox ID="TextBox3" runat="server" autocomplete="off"></asp:TextBox>

or

Textbox1.Attributes.Add("autocomplete", "off");

Upvotes: 1

curious
curious

Reputation: 163

It's a textbox which won't erase what's typed inside it when you hide it. If you're only hiding it, re-showing it will have what you typed in it before. You need to have some functionality to clear the text when you close it. Hard to suggest what to do with the limited question.

Upvotes: 0

Related Questions