Solved

Javascript alter innerHTML of asp:Label control

Posted on 2004-04-02
6
1,740 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
  • 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
Free Tool: Postgres Monitoring System

A PHP and Perl based system to collect and display usage statistics from PostgreSQL databases.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
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

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Summary: Persistence is the capability of an application to store the state of objects and recover it when necessary. This article compares the two common types of serialization in aspects of data access, readability, and runtime cost. A ready-to…
Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.

808 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