Javascript alter innerHTML of asp:Label control

Posted on 2004-04-02
Last Modified: 2008-03-10
I have:


             <img class="ImageButton" src="../image/ico_exclude.gif"
              onclick="<%# _oForm.FindControl(Page.Controls, "lblRealizacao").ClientID %>.innerHTML='This appears on the page but not on server side!!!'>
             <asp:Label id="lblRealizacao" CssClass="Description" runat="server" />


// These lines returns "" (empty) instead of "This appears on the page but not on server side!!!"
((Label) _oForm.FindControl( Page.Controls,"lblRealizacao")).Text ....
lblRealizacao.Text ....

_oForm.FindControl is simple a recursive function that search the page.controls for the ID passed in the parameter.


Thank you!
Question by:3DGames
  • 3
  • 2

Expert Comment

ID: 10743193
Besides an unbalanced number of quotes (maybe just a typo):
onclick="<%# _oForm.FindControl(Page.Controls, "lblRealizacao").ClientID %>.innerHTML='This appears on the page but not on server side!!!'>

To use the quotes inside the onclick="";
You should use \"
For example:
onclick="<%# _oForm.FindControl(Page.Controls, \"lblRealizacao\").ClientID %>";

Besides those syntax, I'm not familiar with it enough to know why it doesn't work.

Expert Comment

ID: 10743308
take a look at this example
this is a common way of attaching javascript to your control

Author Comment

ID: 10743676
No... the quotes are ok in the code, only here i've put some more. (this site layout sucks...)

And the example in the passed link have no usefull information on this case.
I'm using that on delete confirmation.

But here i want:
1-) that a javascript alter de value of a HTML span (asp:label).
2-) it DID it well
3-) after the post back, the value didn't stayed at the client side (???)

Capice? Did I explained it well?
Sorry for my bad english.
Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.


Accepted Solution

gillit earned 500 total points
ID: 10743922
Information are only sent back through forms from the client. Within the forms, the information is sent through inputs. So from what I understand, the problem is that your value is in a label which is not an input field.

I think what you need to do is somehow set the value in an input field (eg textbox, button, hidden) as well as changing the text. This will require that you have a way to retrieve the value.

Hoping this helps.

Author Comment

ID: 10744085
Genius you are!!

In my ignorance I wouldn't realize it...


Expert Comment

ID: 10744478
Glad I could help.

Featured Post

Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

Join & Write a Comment

Introduction                                                 Was the var keyword really only brought out to shorten your syntax? Or have the VB language guys got their way in C#? What type of variable is it? All will be revealed.   Also called…
Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
Here's a very brief overview of the methods PRTG Network Monitor ( offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…
You have products, that come in variants and want to set different prices for them? Watch this micro tutorial that describes how to configure prices for Magento super attributes. Assigning simple products to configurable: We assigned simple products…

706 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now