473,395 Members | 1,696 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,395 software developers and data experts.

Hiding panel controls from Javascript

Hello group:

I'm trying to hide a panel control in javascript when a print button
is clicked. On my web form, I have a button that fires a javascript
function called doPrint(). No matter how I attempt to write the line
to reference the panel control, I get a Null error or an Object does
not exist error. I know this can be done in asp.net, but I need the
event to fire at the client, otherwise the page will print before
firing the server-side code to hide the panel. Here is what I'm
attempting:

<script language="javascript">
function doPrint()
{
var a = document.myForm.pnlMyPanel
a.visible = false;
window.print();
a.visible = true;
}

</script>

What do I need to do?

Thanks,

James
Nov 18 '05 #1
4 17002
Not sure if this is your problem but this has happened to
me before...if the panel is declared with visible="false"
in the html like this...

<html>
<body>
...
<asp:panel id="pnl" runat="server" visible="false" />
</body>
</html>

....javascript will not be able to reference it.

-----Original Message-----
Hello group:

I'm trying to hide a panel control in javascript when a print buttonis clicked. On my web form, I have a button that fires a javascriptfunction called doPrint(). No matter how I attempt to write the lineto reference the panel control, I get a Null error or an Object doesnot exist error. I know this can be done in asp.net, but I need theevent to fire at the client, otherwise the page will print beforefiring the server-side code to hide the panel. Here is what I'mattempting:

<script language="javascript">
function doPrint()
{
var a = document.myForm.pnlMyPanel
a.visible = false;
window.print();
a.visible = true; }

</script>

What do I need to do?

Thanks,

James
.

Nov 18 '05 #2
Thanks for the reply. The suggestion you offered does not apply in my
case; I only have the id, runat, and height properties set.

James
*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Nov 18 '05 #3
Hi James,
Thank you for using Microsoft Newsgroup Service. Based on your description,
you want to hidden a ASP.NET Panel server

control in the client javascript. Is my understanding correct?

If so, here is my suggestion on this issue:
Generally in ASP.NET most ServerControls have the Visible attribute which
can be set in server-side code to show/hide

them. However, you need to know that the ASP.NET servercontrols are not
really HTML element, when render into

browser, the ASP.NET will output them as the proper html element in terms
of the client's browser's capability. For

example, as for the Panel server control, such as
<asp:Panel id="pnlTest" runat="server">
In the Panel
</asp:Panel>

When you run the page and view its html source via the "View Source"
MenuItem, you will find that there is no "Panel"

element in the client html doucment, the "Panel" is represened by a "div"
like:
<div id="pnlTest">
In the Panel
</div>
We still can identify it via the "id", this will remain from serverside to
client.

Also, in clientside javascipt, you can manipulate the html element's
attribute via the DOM object. To show or hide an

element, you need to set its "display" attribute in its css style. Do
remember that no "Visible" attribute in html , it is

abstracted by the ASP.NET in serverside. And here is a simple page shows
how to hide the panel(div) via change its "

display" attribute in client side script:

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" >
<HTML>
<HEAD>
<title>ClientSide</title>
<meta content="Microsoft Visual Studio .NET 7.1" name="GENERATOR">
<meta content="C#" name="CODE_LANGUAGE">
<meta content="JavaScript" name="vs_defaultClientScript">
<meta content="http://schemas.microsoft.com/intellisense/ie5"
name="vs_targetSchema">
<script language=javascript>
function doHide()
{
document.all("pnlTest").style.display = "none";
}
function doShow()
{
document.all("pnlTest").style.display = "inline";
}
</script>
</HEAD>
<body>
<form id="Form1" action="WebForm1.aspx" method="post" runat="server">
<table width="500" align="center" border="1">

<tr>
<td>
<asp:Panel id="pnlTest" runat="server">
<asp:TextBox id="TextBox1" runat="server"></asp

:TextBox>
<asp:Button id="Button1" runat="server" Text="

Button"></asp:Button>
<asp:Label id="Label1" runat="server">Label</asp

:Label>
</asp:Panel>
</td>
</tr>
<tr>
<td><input type=button id="btnHide" name="btnHide" value="Hide

Panel" onclick="doHide()" /></td>
<td><input type=button id="btnShow" name="btnShow" value="Show

Panel" onclick="doShow()" /></td>
</tr>
</table>
</form>
</body>
</HTML>
Please try out the preceding suggestion to see whether it helps. If you
have any questions on it, please feel free to let me know.
Steven Cheng
Microsoft Online Support

Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)

Nov 18 '05 #4
Steven,

Thanks! That worked beautifully! I had already noticed the "div" tag you
mentioned, but I still wasn't sure how to reference it.

Thanks again,

--
James Lankford
"Steven Cheng[MSFT]" <v-******@online.microsoft.com> wrote in message
news:Mn**************@cpmsftngxa07.phx.gbl...
Hi James,

Thank you for using Microsoft Newsgroup Service. Based on your description,
you want to hidden a ASP.NET Panel server control in the client javascript.
Is my understanding correct? If so, here is my suggestion on this issue:

Generally in ASP.NET most ServerControls have the Visible attribute which
can be set in server-side code to show/hide them. However, you need to know
that the ASP.NET servercontrols are not really HTML element, when render
into browser, the ASP.NET will output them as the proper html element in
terms of the client's browser's capability. For example, as for the Panel
server control, such as <asp:Panel id="pnlTest" runat="server">
In the Panel </asp:Panel>

When you run the page and view its html source via the "View Source"
MenuItem, you will find that there is no "Panel" element in the client html
doucment, the "Panel" is represened by a "div" like:
<div id="pnlTest">
In the Panel
</div>
We still can identify it via the "id", this will remain from serverside to
client.

Also, in clientside javascipt, you can manipulate the html element's
attribute via the DOM object. To show or hide an element, you need to set
its "display" attribute in its css style. Do remember that no "Visible"
attribute in html , it is abstracted by the ASP.NET in serverside. And here
is a simple page shows how to hide the panel(div) via change its "display"
attribute in client side script:

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" >
<HTML>
<HEAD> <title>ClientSide</title>
<meta content="Microsoft Visual Studio .NET 7.1" name="GENERATOR">
<meta content="C#" name="CODE_LANGUAGE">
<meta content="JavaScript" name="vs_defaultClientScript">
<meta content="http://schemas.microsoft.com/intellisense/ie5"
name="vs_targetSchema">
<script language=javascript>
function doHide()
{
document.all("pnlTest").style.display = "none";
}
function doShow()
{
document.all("pnlTest").style.display = "inline";
}
</script>
</HEAD>
<body>
<form id="Form1" action="WebForm1.aspx" method="post" runat="server">
<table width="500" align="center" border="1">

<tr>
<td>
<asp:Panel id="pnlTest" runat="server">
<asp:TextBox id="TextBox1" runat="server"></asp

:TextBox>
<asp:Button id="Button1" runat="server" Text="

Button"></asp:Button>
<asp:Label id="Label1" runat="server">Label</asp

:Label>
</asp:Panel>
</td>
</tr>
<tr>
<td><input type=button id="btnHide" name="btnHide" value="Hide

Panel" onclick="doHide()" /></td>
<td><input type=button id="btnShow" name="btnShow" value="Show

Panel" onclick="doShow()" /></td>
</tr>
</table>
</form>
</body>
</HTML>
Please try out the preceding suggestion to see whether it helps. If you
have any questions on it, please feel free to let me know.
Steven Cheng
Microsoft Online Support

Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)

Nov 18 '05 #5

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

Similar topics

0
by: Paul | last post by:
Hi I have a hidden Panel (DIV, style.visibility='hidden') control containing a hidden TextBox. If I make the Panel visible, then make the TextBox visible and then re-hide the Panel the...
3
by: MDB | last post by:
This may sound like a naive question, but that's only because I'm naive about most things ASP.NET, as my background is primarily Lotus Notes Development, and before that, DOS-based FoxPro. Is...
3
by: Charlie Dison | last post by:
Hi There, Should I be able to show and hide panels in an asp.net page without requiring a postback? I thought there was a way to do this using java script. Can anyone give me an example? I...
1
by: Doug | last post by:
Looking for opinions/suggestions: Suppose I have a "region" of an aspx page I want to hide or show based on whatever runtime conditions. Additionally, the entire region is defined by an HTML...
2
by: BobRoyAce | last post by:
I am brand new to ASP.NET and am now required to take over maintenance of a ..NET/C# web application. On one of the pages I'm working on there is a DataGrid which has multiple columns. One of the...
6
by: wandali | last post by:
Hello, I have a problem in finding the status of a panel (visible or not). I have a dropdownlist that associates with a panel in which textbox are embeded in the panel. A client side VBScript is...
22
by: Mr Newbie | last post by:
I was thinking about developing a workflow application yesterday and was musing over the different approaches than one could take in restricting specific actions on a ticket( Form ) at any said...
162
by: Sh4wn | last post by:
Hi, first, python is one of my fav languages, and i'll definitely keep developing with it. But, there's 1 one thing what I -really- miss: data hiding. I know member vars are private when you...
2
by: =?Utf-8?B?TUNN?= | last post by:
I have an asp.net page that contains an update panel. Within the update panel, controls get added dynamically. During partial page post backs the controls within the panel will change. I have a...
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
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
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
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
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.