Wrox Programmer Forums

Need to download code?

View our list of code downloads.

| FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
ASP.NET 1.0 and 1.1 Basics ASP.NET discussion for users new to coding in ASP.NET 1.0 or 1.1. NOT for the older "classic" ASP 3 or the newer ASP.NET 2.0.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the ASP.NET 1.0 and 1.1 Basics section of the Wrox Programmer to Programmer discussions. This is a community of tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
 
 
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old June 9th, 2003, 04:32 AM
Authorized User
 
Join Date: Jun 2003
Location: , , United Kingdom.
Posts: 15
Thanks: 0
Thanked 1 Time in 1 Post
Send a message via MSN to james_sellwood
Default Opening New Window

I have created a page which searches my database and then writes information to the page using an <asp:Label> control. I would like to write the information to a new browser window, rather than to the one with the search elements on it.

?Is it possible to open a new window using VB.NET? (I can use session variables to pull the content across into the new window once it is open.)

My JavaScript is pretty good and I am aware of how to use the
Code:
 window.open("","","")
method. The thing is I need to be able to trigger the new window opening within the VB.NET code of my aspx page upon completion of searching the database (not when the user clicks on a link or button).

Any ideas, info or solutions would be appreciated.

Thanks


--------------------
:) James Sellwood :)
--------------------
__________________
--------------------
James Sellwood
--------------------
  #2 (permalink)  
Old June 9th, 2003, 05:16 AM
Authorized User
 
Join Date: Jun 2003
Location: , , United Kingdom.
Posts: 15
Thanks: 0
Thanked 1 Time in 1 Post
Send a message via MSN to james_sellwood
Default

I have been working on this and found a way or doing it. I would appreciate if anyone can tell me a better way though.

On Page:
Code:
<asp:Label id="jsOutput" runat="server"></asp:Label>
In Code after database search complete:
Code:
jsOutput.text = "<script language='JavaScript'> open('newpage.aspx','results','') </scri" & "pt>"
I found I had to create the code </script> by concatenating it from two parts otherwise it ended by VB script at that point even though it was in quotations.

--------------------
:) James Sellwood :)
--------------------
  #3 (permalink)  
Old June 9th, 2003, 11:24 AM
Authorized User
 
Join Date: Jun 2003
Location: Lexington, KY, USA.
Posts: 46
Thanks: 0
Thanked 1 Time in 1 Post
Default

Your solution is pretty close.

ASP.NET provides the RegisterClientScriptBlock and RegisterStartupScript methods (they are methods of the Page object, but for some reason intellisense doesn't show them, you have to type them yourself).

In your case, I would use the RegisterClientScriptBlock method:

RegisterClientScriptBlock("OpenNew", _
"<script language='JavaScript'> open('newpage.aspx','results',''); </script>")

You don't need the label element on the page at all.

Doing it this way, I've never had to hide the fact that it's a script.

For general purposes, it's considered prudent to put the script inside a HTML comment block:

"<script language='JavaScript'></script>"

This is just for browsers that don't support scripts, which are pretty rare these days.



-Van
(Old dog learning new tricks...)
  #4 (permalink)  
Old June 9th, 2003, 12:04 PM
Authorized User
 
Join Date: Jun 2003
Location: , , United Kingdom.
Posts: 15
Thanks: 0
Thanked 1 Time in 1 Post
Send a message via MSN to james_sellwood
Default

Thanks for the suggestion.

I've had a go and had a look at Microsoft's Class Library. I still had the problem of the </script> tag ended the VB.NET code and therefore had to concatenate that as before. (This method is used by Microsoft within the Class Library example for RegisterClientScriptBlock(). I also had problems triggering the clientside code from within my VB.NET subprocedure (as it is not called by a button or the like).

I am aware of the
Code:
<!--

//-->
comments being used to hide the JavaScript from the older browsers but adding this to my code stopped it working!? so I have had to leave it out.

I think I may be doing something wrong with the RegisterClientScriptBlock(), surely it must be accessible from within the VB.NET subprocedure.

I have registered the client side function like so:
Code:
Sub Page_Load(Sender as Object, e as System.EventArgs)

Dim csScript as String = "<script language='JavaScript'> function openWin(){"
csScript += " open('newpage.aspx','newpage','') } </scr" & "ipt>"
RegisterClientScriptBlock("NewWin",csScript)

End Sub
I am trying to call this clientside code from another subprocedure. How do I actually call the code? Do I not need the code in a function?

Once again thanks for your help in advance.

--------------------
:) James Sellwood :)
--------------------
  #5 (permalink)  
Old June 12th, 2003, 09:34 AM
Authorized User
 
Join Date: Jun 2003
Location: Lexington, KY, USA.
Posts: 46
Thanks: 0
Thanked 1 Time in 1 Post
Default

Well, I'm not really clear what you're trying to do, but guessing from the original post, "I need to be able to trigger the new window opening within the VB.NET code of my aspx page upon completion of searching the database (not when the user clicks on a link or button)."...

I assume you have a sub on the server that is querying the database, because a thin client can't do that.

But from your description, it seems you have a browser sitting there displaying something, and waiting for a database query. That part I don't understand, because HTTP is a connectionless protocol. The server cannot just send something to the browser when it gets ready. The browser has to request it. So the user [u]has</u> to click a button or there [u]has</u> to be a script that works on a timer and reposts to the server, or [u]something</u>...

So, for the next step, I'm too confused without more info.

But I can say this: no, you don't have to have javascript inside a function. If you want the browser to execute it immediately as it loads the page, you can just put out a script like:

<script>
openWin();
</script>



-Van
(Old dog learning new tricks...)
  #6 (permalink)  
Old June 12th, 2003, 11:43 AM
Friend of Wrox
Points: 3,489, Level: 24
Points: 3,489, Level: 24 Points: 3,489, Level: 24 Points: 3,489, Level: 24
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2003
Location: Central, NJ, USA.
Posts: 1,102
Thanks: 0
Thanked 2 Times in 2 Posts
Default

If your goal is to call a routine at whim it needs to be inside a function or subroutine that you then call when you need it. If it's in the page_Load it will just run when the page is loaded... It doesn't let you call it

Hal Levy
Daddyshome, LLC
 


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Opening a New Window GailCG ASP.NET 2.0 Basics 14 April 1st, 2008 11:32 AM
opening a webpage in a new window riyadsmail ASP.NET 1.0 and 1.1 Basics 3 August 31st, 2007 06:56 AM
opening a new window rgpassey Javascript How-To 2 September 14th, 2005 11:38 AM
Opening New Window p_nut33 Classic ASP Basics 1 August 6th, 2004 08:11 PM
Close Parent window on opening child window pkdev Javascript How-To 8 April 11th, 2004 12:06 PM



All times are GMT -4. The time now is 08:45 PM.


Powered by vBulletin®
Copyright ©2000 - 2019, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.