Thursday, March 22, 2012

Set Label Value using Javascript

Hello All,
This may be a silly question to ask - but for some reason I am unable
to get this to work! I have a server control that renders a Label and a
linkbutton, and I have a Javascript (which is registered using
RegisterClientScriptBlock) which has a client function for the OnClick
of the linkButton. All i am trying to set is a value on the label when
the user clicks on the linkButton. I know the javascript onclick is
being called (tested it using an Alert call) and the script does not
throw any errors, but does not set any values of the label either. In
the javascript I set the value using IdOfLabel.value='Text' and it
dosent seem to work! Any thoughts or suggestions would be helpful.
Thanks in advance
Regards,
Chrisdo a view-source of the page and see what it's being rendered to. You may
have to make an InnerHTML call or some other such javascript call, depending
on what it's rendering as.
Curt Christianson
site: http://www.darkfalz.com
blog: http://blog.darkfalz.com
"chrispragash@.hotmail.com" wrote:

> Hello All,
> This may be a silly question to ask - but for some reason I am unable
> to get this to work! I have a server control that renders a Label and a
> linkbutton, and I have a Javascript (which is registered using
> RegisterClientScriptBlock) which has a client function for the OnClick
> of the linkButton. All i am trying to set is a value on the label when
> the user clicks on the linkButton. I know the javascript onclick is
> being called (tested it using an Alert call) and the script does not
> throw any errors, but does not set any values of the label either. In
> the javascript I set the value using IdOfLabel.value='Text' and it
> dosent seem to work! Any thoughts or suggestions would be helpful.
> Thanks in advance
> Regards,
> Chris
>
try using innerHTML or innerText as it is render as span tag ...
"chrispragash@.hotmail.com" wrote:

> Hello All,
> This may be a silly question to ask - but for some reason I am unable
> to get this to work! I have a server control that renders a Label and a
> linkbutton, and I have a Javascript (which is registered using
> RegisterClientScriptBlock) which has a client function for the OnClick
> of the linkButton. All i am trying to set is a value on the label when
> the user clicks on the linkButton. I know the javascript onclick is
> being called (tested it using an Alert call) and the script does not
> throw any errors, but does not set any values of the label either. In
> the javascript I set the value using IdOfLabel.value='Text' and it
> dosent seem to work! Any thoughts or suggestions would be helpful.
> Thanks in advance
> Regards,
> Chris
>
labels don't have a value property. use the innerHTML property instead. if
the link button is nested inside the label, then you will have to use the
dom node interface, and find the actual text node.
-- bruce (sqlwork.com)
<chrispragash@.hotmail.com> wrote in message
news:1125410681.238993.155190@.g47g2000cwa.googlegroups.com...
> Hello All,
> This may be a silly question to ask - but for some reason I am unable
> to get this to work! I have a server control that renders a Label and a
> linkbutton, and I have a Javascript (which is registered using
> RegisterClientScriptBlock) which has a client function for the OnClick
> of the linkButton. All i am trying to set is a value on the label when
> the user clicks on the linkButton. I know the javascript onclick is
> being called (tested it using an Alert call) and the script does not
> throw any errors, but does not set any values of the label either. In
> the javascript I set the value using IdOfLabel.value='Text' and it
> dosent seem to work! Any thoughts or suggestions would be helpful.
> Thanks in advance
> Regards,
> Chris
>

0 comments:

Post a Comment