views:

312

answers:

1

How can I handle click event to Web readonly TextBox in c#

A: 

Take a look at OnClick Event for Text Box in ASP.NET with C#:

indeed TextBox doesn't have Click event at server-side. One reason is that it wouldn't necessarily be reasonable to cause a postback to clear a TextBox (server-side event requires server-side action to occur e.g also a postback).

But, textBox is a web control which supports expando attributes, that is, any attribute added to the control tag which doesn't match any member of the control, is arendered out as is to the markup. So you could in fact use this to create a javascript click action to clear the TextBox. Either set this on aspx

<asp:TextBox ID="TextBox1" runat="server" OnClick="this.value=''"/>

or this in code

Me.TextBox1.Attributes("onclick") = "this.value=''"
Moayad Mardini