1

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.

Ishan
  • 4,008
  • 32
  • 90
  • 153
  • 1
    Just look what visible actually does http://msdn.microsoft.com/en-us/library/system.web.ui.control.visible.aspx – Sly Apr 02 '12 at 10:32

4 Answers4

4

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"

mshsayem
  • 17,557
  • 11
  • 61
  • 69
1

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';
Community
  • 1
  • 1
Pedro Ferreira
  • 629
  • 3
  • 8
0

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

Neil Hodges
  • 127
  • 2
  • 6
  • 15
0

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");
scartag
  • 17,548
  • 3
  • 48
  • 52