Friday, April 29, 2011

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?

with the orginal text i mean the text that is hard coded into the asp.net markup.

From stackoverflow
  • 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.

  • 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. Not sure how this would work in practice though.

0 comments:

Post a Comment