open new browser window - asp.net

S

sri_san

Hello,
I am working on a page where I need to open a new webpage on a
button click. I tried using javascript's window.open but with popup
blocker enabled, it doesnt seem to work. Any way to get away with the
popup blocker?

This is being used to generate some business reports and not with
bad intension.

Any help would be great!!
Sam.
 
T

TDAVISJR

The pop-up blocker is doing what it suppose to do, to get around it you
probably have to turn it off or tell it to not block pop-ups for this
website. You can't have it both ways.
 
M

Marina

Nope, not going to happen as far as I know. Your users will need to allow
popups on your site.
 
B

Bruce Barker

have the button client onclick open the window, or use an anchor

<button value="Open Report"
onclick="window.open('myReport.aspx?id=1234')">
<a href="myReport.aspx?id=1234" target="Popup">Open Report</a>

-- bruce (sqlwork.com)
 
S

Steve C. Orr [MVP, MCSD]

You can do it with a hyperlink, like this:

<a href="SomePage.aspx" target="_blank">Click Me</a>
 
G

Guest

I suggest that you display a prompt to the user of your application asking
her to enable browser popups for the application.
 
S

sri_san

Thanks for the reply. I am considering the hyperlink but can I
superimpose a hyperlink on a command button. In other words, I need to
have an event handler in the same page so as to do some processing
before going to the new page. Can it be done?

Thanks,
Sam.
 
G

Guest

Yes it can be done.

<html>
<head>
<script language="javascript">
function DoProcessing()
{
alert('DoProcesssing()');
}
</script>
</head>
<body>
<form>
<a href="somewebpage.htm" onclick="DoProcessing()">click me</a>
</form>
</body>
</html>
 
S

sri_san

Sorry for being unclear. The processing would be server side. Any
ideas?

Thanks,
Sam.
 
G

Guest

Ah, if you are using ASP.NET then use a "LinkButton" and write code for it's
click event and then make sure to issue a Response.Redirect() to the desired
web page.

If you are not using ASP.NET then you'll need to use some javascript to
perform a form POST to a web page that can perform the processing and then
redirect to the desired web page.

(i.e. posting to an ASP page to perform the processing, and setting a hidden
variable)

<html>
<head>
<script language="javascript">
function DoProcessing(arg)
{
document.all['hiddenarg'].value = arg;
document.forms[0].submit();
}
</script>
</head>
<body>
<form action="process.asp" method="post">
<input type="hidden" id="hiddenarg" value="">
<a href="#" onclick="DoProcessing('123')">click me</a>
</form>
</body>
</html>
 
S

sri_san

Thanks again for the reply. Response.Redirect wouldnt work for me coz
I have to open up the rpt in a new webpage.
I can do the javascript as above and have a hyperlink attached the
javascript function but I believe the javascript function call and the
opening of the rpt in a new page would be asynchronous.I believe as
soon as the script execution is done, one wouldnt have control over the
sequence of events. In other words, the new page (new browser popup
window)should open up after the server code is executed. I would want
the events to be in sync. Example:

<asp:hyperlink id=hypProcess runat=server onclick="DoProcessing()"
navigateURL="rpt.aspx" target="_blank"/>

The function would submit the form but then the rpt.aspx would open up
independent of the form processing, rite?

Thanks,
Sam.
 
G

Guest

I think you have 2 options here:

1) use a regular anchor link <a> that has an href that points to the page
that does the real work and contains the target = "_blank"

i.e.
<a href="rpt.aspx" target="_blank"/>

The rpt.aspx can then do the server side processing that the first page was
doing.

2) Use XMLHttp and some javascript to post data to the first page and then
going to the rpt.aspx.

<html>
<head>
<script language="javascript">
function PostToServer()
{
//Simulate posting to server with XMLHttp - see REF
for(var i=0; i < 20000; i++)
{
window.status = i;
}

return true;
}
</script>
</head>
<body>
<a href="rpt.aspx" onclick="return PostToServer()"
target="_blank">click me</a>
</body>
</html>

REF: http://www.4guysfromrolla.com/webtech/110100-1.shtml

HTH,
Jorge
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,007
Latest member
obedient dusk

Latest Threads

Top