Reputation: 81
This code nested in an ascx control. the onclientclick event works and there are no error but the label text is not changed? What am I missing?
<asp:Button
ID="btnUpload" runat="server" CssClass="Uploadbtn1" OnClientClick="BePatient()" OnClick="btnUpload_Click"
Text="Upload" Width="62px" align="center"/>
<Label ID="Label1" ></Label>
<br />
<br />
<asp:Label ID="ErrorMessageLbl" runat="server"></asp:Label>
<script type="text/javascript" language="javascript">
function BePatient() {
var lbl = document.getElementById('<%=ErrorMessageLbl.ClientID%>');
var lblText = lbl.getAttribute("innerText");
// var lblText = lbl.getAttribute("Text"); // this did not work
//var lblText = lbl.getAttribute("innerHtml"); // this did not work
lbl.setAttribute(lblText, "Please be patient this will take awhile!");
}
</script>
Upvotes: 0
Views: 344
Reputation: 102753
The way you set an element's text is like this:
var lbl = document.getElementById('<%=ErrorMessageLbl.ClientID%>');
lbl.innerText = "Please be patient this will take awhile!";
If for some reason you actually wanted to set an attribute named 'innerText', then you'd use
var lbl = document.getElementById('<%=ErrorMessageLbl.ClientID%>');
lbl.setAttribute('innerText', 'Please be patient this will take awhile!');
Upvotes: 2