gpt4 book ai didi

c# - 如何在 C# 中处理对 Web 只读 TextBox 的单击事件

转载 作者:太空宇宙 更新时间:2023-11-03 16:56:26 24 4
gpt4 key购买 nike

如何在 C# 中处理 Web 只读文本框的点击事件

最佳答案

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

关于c# - 如何在 C# 中处理对 Web 只读 TextBox 的单击事件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1733472/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com