Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get Label inner text from Codebehind

Tags:

html

c#

asp.net

I have html label contol without runat="server"

Does it possible to get inner text from code behind c#?

Label:

<label id="lblClanName">Text Here</label>

Thanks

like image 650
Irakli Lekishvili Avatar asked Aug 29 '26 22:08

Irakli Lekishvili


1 Answers

Every time an ASP.Net page is posted back to the server it is recreated from scratch using the custom code contained in the page (such as calls to a database), the HTTP post/get collections (which include ViewState), any custom data in Application, Cache, Session, static objects, etc.

If the value does not exist in any of those locations, the server doesn't have access to it. A common trick to pass data from the client is to simply use a hidden field. If you want something more elegant, you can use asynchronous AJAX to send/receive data from the server.

Or in this case, you could just add runat="server" to an asp:Label. ViewState will maintain the value between postbacks, though it will not reflect changes made client-side unless (once again) the data is somehow passed back to the server.

Note that ViewState is typically a bad thing because it essentially doubles the size of your data (or more) and (in my opinion) encourages sloppy design.

like image 55
Tim M. Avatar answered Aug 31 '26 16:08

Tim M.



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!