nav
nav

Reputation: 509

ASP:Label, span and javascript elementbyId access

I am currently trying to access a control that is within a class.

HTML Code:

   <span class="GeoPanelHeaderLeft">
       <asp:Literal ID="LiteralHeaderText" runat="server" Text="New Survey Ticket"></asp:Literal>
     &nbsp
      &nbsp
      &nbsp
       <asp:Image ID = "errorImg" runat = "server" ImageUrl="..\Images\caution_red.gif" visible        = "false"/>
     <asp:Label ID = "literalerrortext2" runat="server" ClientIDMode= "Static"></asp:Label>
    <asp:Label ID = "literalerrortext3" runat="server" ClientIDMode= "Static"></asp:Label>
     <asp:Label ID = "LiteralErrorText" runat="server" ClientIDMode="Static" ></asp:Label>

JavaScript Code:

   function setError(message) {
            var test = window.document.getElementById("LiteralErrorText");
            var test2 = window.document.getElementById("literalerrortext2");
                var test3 = window.document.getElementById("literalerrortext3");


      }

When I run my javascript function, the getElementById function returns objects for "literalerrortext2" and "literalerrortext3", however the object is null when it comes to "LiteralErrorText".

I am using master pages and not sure why this is happening. If anyone can help with this that would be awesome.

Thanks

Upvotes: 3

Views: 285

Answers (1)

puddleglum
puddleglum

Reputation: 1045

Your Literal control is rendered literally as New Survey Ticket (no html unless you choose to put it there)... unlike your Label controls which are rendered as <span id=myid>Some text</span>.

Upvotes: 2

Related Questions