473,385 Members | 2,028 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

server controls and Page Methods

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
Jan 17 '08 #1
3 1680


<ja*************@gmail.comwrote in message
news:26**********************************@e25g2000 prg.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

Jan 17 '08 #2

<ja*************@gmail.comwrote in message
news:26**********************************@e25g2000 prg.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 <spanelement, which may or may not contain the functionality you desire.
Personally, I would wrap the label in a <divelement and then toggle the
visibility of the <div>.

Jan 17 '08 #3


"Scott Roberts" <sr******@no.spam.here-webworks-software.comwrote in
message news:OM**************@TK2MSFTNGP06.phx.gbl...
>
<ja*************@gmail.comwrote in message
news:26**********************************@e25g2000 prg.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 <spanelement, 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

Jan 17 '08 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Brian | last post by:
NOTE ALSO POSTED IN microsoft.public.dotnet.framework.aspnet.buildingcontrols I have solved most of my Server Control Collection property issues. I wrote an HTML page that describes all of the...
5
by: serge calderara | last post by:
Dear all, I am new in asp.net and prepare myself for exam I still have dificulties to understand the difference between server control and HTML control. Okey things whcih are clear are the fact...
2
by: Mike | last post by:
Hi, I am strugling with a simple problem which I can't seem to resolve. I have an asp.net page which contains a server-control (flytreeview, which is a kind of a tree to be exact). The tree is...
2
by: Jobs | last post by:
Download the JAVA , .NET and SQL Server interview with answers Download the JAVA , .NET and SQL Server interview sheet and rate yourself. This will help you judge yourself are you really worth of...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.