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
joteke
All-Star
46284 Points
6896 Posts
ASPInsiders
MVP
Re: OnClick Event for Text Box in ASP.NET with C#
Mar 09, 2007 03:37 PM|LINK
Hi,
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=''"
Teemu Keiski
Finland, EU