Click here to Skip to main content
15,892,269 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
HI all,

I have a weird problem in my page. I have a button called Print. I wanted report should come in a new tab, so i wrote some javascript on button's onClientClick. Which works great with no problem at all.

But problem starts now when user comes back on original page again, now here i have several controls which cause postback. Say for example its a dropdownlist. so whenever user changes dropdown item it causes postback which is fine but everytime it opens a new tab on every postback.

hope I am clear in question...

Any help??

Here is a code:

ASP.NET
<asp:button ID="btnPrint" runat="server" Text = "Print" OnClick="btnPrint_Click" onClientClick="aspnetForm.target='_blank'" />
Posted
Updated 21-Mar-12 22:12pm
v2
Comments
[no name] 22-Mar-12 3:14am    
You need to show your code, what you done and where are you stuck.

Hi,

On page load event check IsPostBack and load you settings according to that.
 
Share this answer
 
Comments
hiren soni 22-Mar-12 3:19am    
that is not really possible because to open a new tab on button click is written on onClientClick so before i get on page load event it has already opened a new tab.
i just clear the target on onLoad like this

JavaScript
opener.document.getElementById('aspnetForm').target = '';


and this works great....:-)
 
Share this answer
 
first of all thanks Hiren, i had a same problem as like you but using your solution i sort it out

in aspx;
inside body section
write the following
C#
<body onload="fixform()"> 


then write a javascript
C#
<script type="text/javascript">
    function fixform() 
    {
        document.getElementById("Form1").target = '';       
    }

remember you have set target ='_blank' onClientClick
for viz.:
C#
<asp:button id="btnPrint" runat="server" text="Print" onclick="btnPrint_Click" onclientclick="Form1.target='_blank'" xmlns:asp="#unknown" />
 
Share this answer
 
good information for newbies...
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900