简体   繁体   English

ASP.NET获取标签的原始文本

[英]ASP.NET Get Original Text of Label

Is there any way to get the original text from a Asp:Label on a page, after the text has been altered? 更改文本后,是否有任何方法可以从页面上的Asp:Label获取原始文本?

with the orginal text i mean the text that is hard coded into the asp.net markup. 带有原始文字的意思是硬编码到asp.net标记中的文字。

There is no standard way to get it back after some chages, but you could do that in some your ways, for example add custom attributes to label 没有标准的方法可以在遇到一些麻烦之后将其取回,但是您可以通过某些方式做到这一点,例如,将自定义属性添加到标签

textLabel.Attributes.Add("data", textLabel.Text);  

and then use it on your page. 然后在您的页面上使用它。 Or cache label value using js code on page startup or statically. 或在页面启动时或静态使用js代码缓存标签值。

Create a property that wraps the text assignment. 创建一个包装文本分配的属性。 Before the assignment take the current value and assign it to a hidden input or stick it in the session or viewstate. 在分配之前,请获取当前值并将其分配给隐藏的输入或将其粘贴在会话或视图状态中。

Create a property that retrieves the previous value from the hidden input or session or viewstate. 创建一个属性,该属性从隐藏的输入或会话或视图状态中检索先前的值。

Could get fancy and extend the label to add a PreviousValue property. 可能会花哨并扩展标签以添加PreviousValue属性。 Not sure how this would work in practice though. 不确定如何在实践中。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM