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

Q: combining Javascript and ASP-function?

Hi,

In an aspx page, I've got a TreeView and a detail form and a print
button. When the user clicks on the print button, I'd like to collapse
the TreeView and send the page to the printer.
Using Javascript, the print is easy:
<asp:ImageButton ID="btnPrint" runat="server" AlternateText="Print"
ImageUrl="~/images/print.gif"
OnClientClick="javascript:window.print();return false;" ToolTip="Print
page" />

However, I'm not able to combine the window.print() function with the
necessary method to collapse the TreeView (MyTreeView.CollapseAll()).

Anyone who's got any pointers on how to combine the Javascript print-
function with the ASP.NET TreeView.Collapse method on a single button?

Thanks!

Regards,
-Haakon-

Apr 16 '07 #1
3 1821
The "return false;" part of the OnClientClick tells the event not to
progress to the server where the collapsing part is handled. Change it to
"return true"

--
Eliyahu Goldin,
Software Developer & Consultant
Microsoft MVP [ASP.NET]
http://msmvps.com/blogs/egoldin
http://usableasp.net
<ha*****@gmail.comwrote in message
news:11*********************@p77g2000hsh.googlegro ups.com...
Hi,

In an aspx page, I've got a TreeView and a detail form and a print
button. When the user clicks on the print button, I'd like to collapse
the TreeView and send the page to the printer.
Using Javascript, the print is easy:
<asp:ImageButton ID="btnPrint" runat="server" AlternateText="Print"
ImageUrl="~/images/print.gif"
OnClientClick="javascript:window.print();return false;" ToolTip="Print
page" />

However, I'm not able to combine the window.print() function with the
necessary method to collapse the TreeView (MyTreeView.CollapseAll()).

Anyone who's got any pointers on how to combine the Javascript print-
function with the ASP.NET TreeView.Collapse method on a single button?

Thanks!

Regards,
-Haakon-

Apr 16 '07 #2
Thanks for the reply. I think I was a bit unclear on what I wanted to
achieve.
I need to collapse my TreeView before I print the page. So going to
the server and collapsing the tree after firing off the browser print
function will not solve my problem.

I tried:

<script runat="server">
void CollapseTree(Object sender, EventArgs e)
{
TreeView1.CollapseAll();
}
</script>

and then:

<asp:ImageButton ID="ImageButton1" runat="server"
AlternateText="Print" ImageUrl="~/images/print.gif"
OnClientClick="CollapseTree;javascript:window.prin t();return true;"
ToolTip="Print page" />

but that results in the error: 'CollapseTree' is undefined - which is
strange, given that I have other ASP-functions that DO work on e.g.
OnSelectedIndexChanged

Regards,
-Haakon-

On Apr 16, 10:46 am, "Eliyahu Goldin"
<REMOVEALLCAPITALSeEgGoldD...@mMvVpPsS.orgwrote:
The "return false;" part of the OnClientClick tells the event not to
progress to the server where the collapsing part is handled. Change it to
"return true"

--
Eliyahu Goldin,
Software Developer & Consultant
Microsoft MVP [ASP.NET]http://msmvps.com/blogs/egoldinhttp://usableasp.net
Apr 16 '07 #3
What you put in OnClientClick runs on client side whereas CollapseTree is a
server side method.

You don't need to use OnClientClick. Instead let CollapseTree do its job and
communicate a request to print to the client side.

This article may help you for the last part:
How to Pass Messages and Actions between Server and Client
http://usableasp.net/DeveloperPage.a...rAndClient.htm

--
Eliyahu Goldin,
Software Developer & Consultant
Microsoft MVP [ASP.NET]
http://msmvps.com/blogs/egoldin
http://usableasp.net
<ha*****@gmail.comwrote in message
news:11**********************@l77g2000hsb.googlegr oups.com...
Thanks for the reply. I think I was a bit unclear on what I wanted to
achieve.
I need to collapse my TreeView before I print the page. So going to
the server and collapsing the tree after firing off the browser print
function will not solve my problem.

I tried:

<script runat="server">
void CollapseTree(Object sender, EventArgs e)
{
TreeView1.CollapseAll();
}
</script>

and then:

<asp:ImageButton ID="ImageButton1" runat="server"
AlternateText="Print" ImageUrl="~/images/print.gif"
OnClientClick="CollapseTree;javascript:window.prin t();return true;"
ToolTip="Print page" />

but that results in the error: 'CollapseTree' is undefined - which is
strange, given that I have other ASP-functions that DO work on e.g.
OnSelectedIndexChanged

Regards,
-Haakon-

On Apr 16, 10:46 am, "Eliyahu Goldin"
<REMOVEALLCAPITALSeEgGoldD...@mMvVpPsS.orgwrote:
>The "return false;" part of the OnClientClick tells the event not to
progress to the server where the collapsing part is handled. Change it to
"return true"

--
Eliyahu Goldin,
Software Developer & Consultant
Microsoft MVP
[ASP.NET]http://msmvps.com/blogs/egoldinhttp://usableasp.net

Apr 16 '07 #4

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

Similar topics

2
by: Brian | last post by:
Hi All, Can someone please point me in the right direction I am having problems combining JS and ASP. What I am trying to do is store in a database using ASP the referring page of my visitors. ...
3
by: alwayswinter | last post by:
I currently have a form where a user can enter results from a genetic test. I also have a pool of summaries that would correspond to different results that a user would enter into the form. I...
5
by: Michael Herman \(Parallelspace\) | last post by:
1. What are some compelling solutions for using Master/Content pages with Web Pages? 2. If a content area has a web part zone with web parts, what is the user experience like when "editting" the...
3
by: Roger | last post by:
Hi there I have several bigger applications programmed with the old ASP (vbscript). A lot of data is stored in the session object. Now I have to extend the application with new functionality...
2
by: fran7 | last post by:
Hi, I wonder if anyone can see whats going wrong here. I have this line of asp and javascript and it works fine <a onmouseover="doTooltip(event,'<img...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
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: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
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: 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...

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.