C # - How to change the value of a text field in focus

I am writing an application in C #. I would like to replace the value for the TEXT property after the user clicks (focuses) on the text box. I want the TEXT value to be empty, instead of the words "ENTER NAME HERE" when they click to edit the text field.

Frontal:

<asp:TextBox Text="ENTER NAME HERE" OnClick="MyTextboxID_OnClick" ID="MyTextboxID" runat="server"></asp:TextBox>

Code for:

protected void MyTextboxID_OnClick(object sender, EventArgs e) 
{
    MyTextboxID.Text = "";
}

I tried to find the answer to this question, but the answers did not quite match what I wanted to do.

I was hoping C # had something similar to Javascript events "OnClick" or "OnFocus". I added the OnClick event to the text box for illustration. This OnClick event is not working.

Thank you in advance for your help!

+4
4

Placeholder="Enter text here."

:

<asp:Textbox id="txtName" runat="server" placeholder="Enter name here." />

:

$("#<%= txtName.ClientId %>").setAttribute('placeholder', 'Enter name here.');
$("#<%= txtName.ClientId %>").attr('placeholder', 'Enter name here.');

Javascript : <script type="text/javascript"></script>. , .

Tooltip. , . . IE 8 Placeholder. , Postback, - Server-Side. Postback, /Ajax, .

+1

, ASP.NET . , #, . , AJAX, "OnClick" ASP.

Javascript "OnClick". Javascript , , .

+4

Javascript, TextBoxWatermark .

NuGet.

<asp:TextBox OnClick="MyTextboxID_OnClick" 
    ID="MyTextboxID" runat="server">
</asp:TextBox>

<ajaxToolkit:TextBoxWatermarkExtender ID="TBWE2" runat="server"
    TargetControlID="MyTextboxID"
    WatermarkText="ENTER NAME HERE"
    WatermarkCssClass="watermarked" />
+2

. , ,

+1

All Articles