admin管理员组

文章数量:1328825

I have this javascript function:

function validateFile() {
            var file = document.getElementById('fuCSV');
            if (file.value == "") {
                document.getElementById('<%=lblStatus.ClientID%>').innerhtml = "Please select a file to upload. Client!";
                return false;
            }
            else {
                document.getElementById('<%=lblStatus.ClientID%>').innerhtml = "";
                return true;
            }
        }

Its called on the Button's OnClientClick event like this:

<asp:Button ID="btnImport" runat="server" Text="Import" OnClientClick="return validateFile();" CausesValidation = "true"
            UseSubmitBehavior ="true" OnClick="btnImport_Click" />

I'm trying to change the text of the label lblStatus on validateFile() method, but the text is not changing. However, while debugging...QuickWatch shows the changed value. What might be the cause for it? how can I resolve this?

I have this javascript function:

function validateFile() {
            var file = document.getElementById('fuCSV');
            if (file.value == "") {
                document.getElementById('<%=lblStatus.ClientID%>').innerhtml = "Please select a file to upload. Client!";
                return false;
            }
            else {
                document.getElementById('<%=lblStatus.ClientID%>').innerhtml = "";
                return true;
            }
        }

Its called on the Button's OnClientClick event like this:

<asp:Button ID="btnImport" runat="server" Text="Import" OnClientClick="return validateFile();" CausesValidation = "true"
            UseSubmitBehavior ="true" OnClick="btnImport_Click" />

I'm trying to change the text of the label lblStatus on validateFile() method, but the text is not changing. However, while debugging...QuickWatch shows the changed value. What might be the cause for it? how can I resolve this?

Share Improve this question asked Oct 20, 2011 at 14:45 NaveenBhatNaveenBhat 3,3284 gold badges40 silver badges48 bronze badges 3
  • 3 innerhtml is just a typo of innerHTML? – Prusse Commented Oct 20, 2011 at 14:48
  • did you try setting innerText as opposed to innerHTML? – Icarus Commented Oct 20, 2011 at 14:51
  • @Prusse: ya...its the case problem...thanks! I have wasted lots of time to find out the cause with no luck!!! – NaveenBhat Commented Oct 20, 2011 at 14:58
Add a ment  | 

4 Answers 4

Reset to default 3

I had suggested to use innerText but apparently, the W3C-pliant way of doing this is to use textContent:

document.getElementById('<%=lblStatus.ClientID%>').textContent = "Please select a file to upload. Client!";

See Mozilla's documentation here.

Use correct casing on the property: innerHTML

http://www.tizag./javascriptT/javascript-innerHTML.php

Javascript is case sensitive, if you set innerhtml property instead of innerHTML you won't see anything.

var e = document.getElementById("fName_err");
e.innerHTML = "** Enter first name";

get the id where you want to give output in e.

本文标签: aspnetJavascript change label39s text via innerhtml not workingStack Overflow