Home > Archive > ASP .NET > January 2008 > server controls and Page Methods
You are viewing an archived Text-only version of the thread.
To view this thread in it's original format and/or if you want to reply to
this thread please [click here]
| Author |
server controls and Page Methods
|
|
| jasonmwilkerson@gmail.com 2008-01-17, 7:18 pm |
| 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
| |
|
|
<jasonmwilkerson@gmail.com> wrote in message
news:26339b3d-0fe8-49ba-a47c-67ea4c3012e7@e25g2000prg.googlegroups.com...
> 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
--
Gianluca Gravina
http://blogs.ugidotnet.org/thinkingingrava
| |
| Scott Roberts 2008-01-17, 7:18 pm |
|
<jasonmwilkerson@gmail.com> wrote in message
news:26339b3d-0fe8-49ba-a47c-67ea4c3012e7@e25g2000prg.googlegroups.com...
> 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" <sroberts@no.spam.here-webworks-software.com> wrote in
message news:OMHEUhSWIHA.4904@TK2MSFTNGP06.phx.gbl...
>
> <jasonmwilkerson@gmail.com> wrote in message
> news:26339b3d-0fe8-49ba-a47c-67ea4c3012e7@e25g2000prg.googlegroups.com...
>
> 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.
--
Gianluca Gravina
http://blogs.ugidotnet.org/thinkingingrava
|
|
|
|
|