Solved

Javascript alter innerHTML of asp:Label control

Posted on 2004-04-02
6
1,736 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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Introduction Hi all and welcome to my first article on Experts Exchange. A while ago, someone asked me if i could do some tutorials on object oriented programming. I decided to do them on C#. Now you may ask me, why's that? Well, one of the re…
Performance in games development is paramount: every microsecond counts to be able to do everything in less than 33ms (aiming at 16ms). C# foreach statement is one of the worst performance killers, and here I explain why.
This video demonstrates how to create an example email signature rule for a department in a company using CodeTwo Exchange Rules. The signature will be inserted beneath users' latest emails in conversations and will be displayed in users' Sent Items…
This is a video that shows how the OnPage alerts system integrates into ConnectWise, how a trigger is set, how a page is sent via the trigger, and how the SENT, DELIVERED, READ & REPLIED receipts get entered into the internal tab of the ConnectWise …

932 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

11 Experts available now in Live!

Get 1:1 Help Now