Ishan
Ishan

Reputation: 4028

Enable a ASP hidden label in Javascript

I Have a asp label

<asp:Label ID="lblstarUKRollNo" Visible="false" runat="server" Text="*" CssClass="star"></asp:Label>

and i want to enable it onchange of another textbox which calls a JS, in my javascript i tried

var idlblstarUKRollNo = '<%= lblstarUKRollNo.ClientID %>';
var lblstarUKRollNo = document.getElementById(idlblstarUKRollNo);

and to enable

reqdddlUKJurisdiction.enabled = true; and lblstarUKRollNo.style.display="block";

Both did not work for me. Can anyone help me How to solve this issue.

Upvotes: 1

Views: 5543

Answers (4)

Pedro Ferreira
Pedro Ferreira

Reputation: 649

Guidance from another question

After adapting to your case:

<asp:Label id="lblstarUKRollNo" style="display: block;" runat="server" Text="*" CssClass="star"/>

Then, you could make it invisible on the client side on Javascript with:

document.getElementById('lblstarUKRollNo').style.display = 'none';

Upvotes: 1

scartag
scartag

Reputation: 17680

In addition to what @mshsyayem above has said you have to set the display to none. and you can do it in the code-behind by using the attributes. See below.

lblstarUKRollNo.Attributes.Add("style", "display:none");

Upvotes: 0

Neil Hodges
Neil Hodges

Reputation: 127

Try using jQuery - $('.someElement').attr('disabled', '');

Upvotes: 0

mshsayem
mshsayem

Reputation: 18008

If you set Visible property to false on a server-control it wont be rendered on the client side at all. So javascript wont be able to find it. Remove Visible property; just use css style "display:none"; later use javascript to change it as "display:block"

Upvotes: 4

Related Questions