Solved

Javascript alter innerHTML of asp:Label control

Posted on 2004-04-02
6
1,744 Views
Last Modified: 2008-03-10
I have:

ASPX

<asp:datagrid.....blablabla
   .....
   <EditItemTemplate>
       <tr>
         <td>
             <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!!!'>
             <br>
             <asp:Label id="lblRealizacao" CssClass="Description" runat="server" />
    </td>
</tr>


CS

// 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.

Why??

Thank you!
0
Comment
Question by:3DGames
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
6 Comments
 
LVL 3

Expert Comment

by:gillit
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.
0
 
LVL 7

Expert Comment

by:TransBind
ID: 10743308
take a look at this example
this is a common way of attaching javascript to your control
http://davidhayden.com/blog/dave/archive/2004/03/16/178.aspx
0
 

Author Comment

by:3DGames
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 came...it stayed at the client side (???)

Capice? Did I explained it well?
Sorry for my bad english.
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 3

Accepted Solution

by:
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.
0
 

Author Comment

by:3DGames
ID: 10744085
Genius you are!!

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

Thanks!
0
 
LVL 3

Expert Comment

by:gillit
ID: 10744478
Glad I could help.
0

Featured Post

Salesforce Made Easy to Use

On-screen guidance at the moment of need enables you & your employees to focus on the core, you can now boost your adoption rates swiftly and simply with one easy tool.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction Although it is an old technology, serial ports are still being used by many hardware manufacturers. If you develop applications in C#, Microsoft .NET framework has SerialPort class to communicate with the serial ports.  I needed to…
Entity Framework is a powerful tool to help you interact with the DataBase but still doesn't help much when we have a Stored Procedure that returns more than one resultset. The solution takes some of out-of-the-box thinking; read on!
Monitoring a network: how to monitor network services and why? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the philosophy behind service monitoring and why a handshake validation is critical in network monitoring. Software utilized …
This tutorial will teach you the special effect of super speed similar to the fictional character Wally West aka "The Flash" After Shake : http://www.videocopilot.net/presets/after_shake/ All lightning effects with instructions : http://www.mediaf…

696 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