Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Set ASP Literal text with Javascript

I have an asp:Literal on my page (which cannot be converted to a Label or any other control) that I need to change the text of via JavaScript. I have the following code that works for a Label. Can anybody help?

<script type="text/javascript">
        function changeText() {
            document.getElementById('<%= Test.ClientID %>').innerHTML = 'New Text';
        }
    </script>

        <a href="#" onclick='changeText()'>Change Text</a>
        <asp:Label id="Test" runat="server" Text="Original Text" />

Thanks


UPDATE: I cannot change from a literal as the code behind writes HTML/CSS to it for an Information Message e.g:
LITMessage.Text = "<div class='success'>Information Successfully Updated</div>"
like image 630
James Avatar asked Feb 09 '11 14:02

James


1 Answers

<asp:Literal> controls don't create their own HTML tag.
Therefore, there is no element that you can manipulate.

Instead, you can wrap the <asp:Literal> in a <div> tag with an ID.

like image 113
SLaks Avatar answered Nov 08 '22 11:11

SLaks