开发者

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

开发者 https://www.devze.com 2022-12-11 04:59 出处:网络
How can I handle c开发者_JS百科lick event to Web readonly TextBox in c#Take a look atOnClick Event for Text Box in ASP.NET with C#:

How can I handle c开发者_JS百科lick event to Web readonly TextBox in c#


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=''"
0

精彩评论

暂无评论...
验证码 换一张
取 消