server controls and Page Methods

  • Thread starter Thread starter jasonmwilkerson
  • Start date Start date
J

jasonmwilkerson

Can you access properties (Text, Visible, etc...) on server controls
(i.e. TextBox, Label, etc...) from javascript? I am trying to toggle
the visibility of a Label clientside.

<script type="text/javascript">
function toggle() {
var label = $get('<%=this.lblMessage.ClientID %>');
if (label != null) {
label.Visible = !label.Visible;
}
}
</script>
<asp:Label ID="lblMessage" runat="server" Text="Hello" />
<asp:Button ID="btnToggle" runat="server"
OnClientClick="toggle();return false;" />

Is this possible?
Thanks!
Jason
 
Can you access properties (Text, Visible, etc...) on server controls
(i.e. TextBox, Label, etc...) from javascript? I am trying to toggle
the visibility of a Label clientside.

<script type="text/javascript">
function toggle() {
var label = $get('<%=this.lblMessage.ClientID %>');
if (label != null) {
label.Visible = !label.Visible;
}
}
</script>
<asp:Label ID="lblMessage" runat="server" Text="Hello" />
<asp:Button ID="btnToggle" runat="server"
OnClientClick="toggle();return false;" />

Is this possible?
Thanks!
Jason

You've got Dom Properties for that:

var label = $get('<%=this.lblMessage.ClientID %>');
if (label.style) {
label.style.display = "hidden";
}
}

Or you can prototype all the properties of Label (for example) and wrap all
methods ... I think it's a suicide !

HTH
 
Can you access properties (Text, Visible, etc...) on server controls
(i.e. TextBox, Label, etc...) from javascript? I am trying to toggle
the visibility of a Label clientside.

<script type="text/javascript">
function toggle() {
var label = $get('<%=this.lblMessage.ClientID %>');
if (label != null) {
label.Visible = !label.Visible;
}
}
</script>
<asp:Label ID="lblMessage" runat="server" Text="Hello" />
<asp:Button ID="btnToggle" runat="server"
OnClientClick="toggle();return false;" />

Is this possible?
Thanks!
Jason

The server controls themselves cannot be manipulated via javascript, but the
HTML generated by the server controls can. I believe that a Label renders as
a <span> element, which may or may not contain the functionality you desire.
Personally, I would wrap the label in a <div> element and then toggle the
visibility of the <div>.
 
Scott Roberts said:
The server controls themselves cannot be manipulated via javascript, but
the HTML generated by the server controls can. I believe that a Label
renders as a <span> element, which may or may not contain the
functionality you desire. Personally, I would wrap the label in a <div>
element and then toggle the visibility of the <div>.

Ops ... yes .. you've got to wrap into a div to set the "display" style !

Sorry.
 
Back
Top