Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to open new browser window from ASP.NET code ???

Status
Not open for further replies.

haroonkhalid

Programmer
Nov 6, 2001
16
SG
hi ..
i want to open new pop up window on button click after fetching some data from server in ASP.NET. How could i do it in ASP.NET code written using VB.NET language like

function button_click(...)

' do some calculations and data manipulation ...

open new window with new URL ... for example
end function

how cud i open this new window ???????????
 
Does the window that is opened depend on any of the calculations? If not you could add a client side script to the on_click event that opens the window.
Use javascript and do a window.open in the client side script. That'l do donkey, that'l do
[bravo] Mark
 
or I believe there is a target "_top" parameter on the Responde.Redirect function. Or it used to be...

hth Daren J. Lahey
Just another computer guy...
 
Daren could you give an example of this using Response.Redirect? I was trying to do this a while back and ended up writing a javascript function as a workaround. That'l do donkey, that'l do
[bravo] Mark
 
I haven't found the target parameter but here is what you have instead:

from the vs.net help
[C#]
public void Redirect(
string url,
bool endResponse
);

Parameters
url - The target location.
endResponse - Indicates whether execution of the current page should terminate.


where the bool parameter is there if you want to terminate the execution of the CURRENT window. Therefore putting that parameter to false will result in a new browser window.

hth Daren J. Lahey
Just another computer guy...
 
What if the button is a server-side control? How can we associate a client-side javascript funcntion with it?
 
U should use the attributes collection of the control:

MyButton.Attributes.Add("onClick", "alert('something');")

The second argument is the client script code. It can call a client script function or execute a command (like in the example). U can also use it to handle other properties, like style (quite usefull) or any other html property or event.
NetAngel
 
The code that follows uses an ASP:button to call a server side sub to open a new window of the specified URL.

Basically, when the button is clicked, the sub is called and uses response.write to write out and execute javascript to open the new window. There is also code in the javascript to resize the window and remove toolbars (ie pop-up style).

You can copy and paste the example and use it to open up a pop up window to TekTips.com.

Good Luck.

Tt

<%@ Page Language=&quot;VB&quot; %>

<SCRIPT RUNAT=&quot;SERVER&quot;>

Sub NewPage(sender As Object, e As System.EventArgs)

response.write(&quot;<script language='javascript'>&quot; & vbcrlf)

response.write(&quot;wndCht=window.open(' height=400,toobar=no,addressbar=no,menubar=no,scrollbars=yes,resizable=yes');&quot;)

response.write(&quot;<&quot; & &quot;/&quot; & &quot;script&quot; & &quot;>&quot; & vbcrlf)

end sub

</SCRIPT>

<HTML>

<BODY>

<FORM runat=&quot;server&quot;>

<ASP:Button id=&quot;btnNewPage&quot;
text=&quot;Open New Page&quot;
runat=&quot;Server&quot;
onClick=&quot;NewPage&quot; />
</FORM>

</BODY></HTML>
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top