Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

like image 733
nav Avatar asked Jan 24 '26 20:01

nav


1 Answers

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>.

like image 177
puddleglum Avatar answered Jan 27 '26 10:01

puddleglum



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!