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 Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

New browser window using VB 1

Status
Not open for further replies.

johpje

Programmer
Jan 3, 2002
87
BE
Hi all,

I need a new browser window to be opened to a give URL from VB code. How can I do this?

I know how to do it in javascript, but i need variables and functions from .NET to specify the acual URL, so I need the VB equivalent of window.open(...)

thanks
Johpje
 
There is none but you can whip up a string that contains your javascript syntax <script language=javascript... then use the RegisterStartupScript method to write the javascript to the page. That javascript is then run when the page is returned to the browser.

Remember VB is a server side langauge and as such cannot directly affect what happens on the client. That'l do donkey, that'l do
[bravo] Mark
If you are unsure of forum etiquette check here faq796-2540
 
Johpje: One technique I use is to allow users to select a specific URL form a drop down box. The user selects a certain feature, say, e.g., a 1 meter aerial photograph located at TerraServer, and then the URL is attached to a simple Response.Redirect statement (I capture the Latitude and Longitude in the URL so the specific aerial opens up for that location). This may not be exactly what you're looking for but thought I'd mention it (a good technique). The code operates as follows:

After the user selects an item from the drop down listbox, they have to click on a &quot;Map!&quot; button to trigger the opening of the URL (you could alternatively set the AutoPostBack on the dd list). Name of listbox is ddMaps. Local variables strLat and strLong hold current Latitude/Longitude values.

<asp:button id=&quot;btnMap&quot; Type=&quot;submit&quot; runat=&quot;server&quot; Text=&quot;Map&quot; OnClick=&quot;btnMaps_Click&quot; />

...then I just have the following routine run on the OnClick event of the button:

Sub btnMaps_Click(Sender as Object, e As EventArgs)
If ddMaps.SelectedItem.Value = 1 Then
Response.Redirect(&quot; & &quot;&Lat=&quot; & strLat & &quot;&Long=&quot; & strLong ...&quot;)
ElseIf...
End If

Simply concatenate the variables (Lat/Long) into the URL and TerraServer opens up at the right place. I have incorporated this technique at several locations thereby making it faster and more efficient to review data/charts/maps at the same time.
 
Zarc:

You submitted same time I did. I have benefited from your &quot;append string&quot; startup routines and that may serve in this purpose. Hope ya had a great holiday.

Izy
 
thanks a lot for replying to both,

I'll give the RegisterStartupScript a try, although it's gonna be a hell of a lot of code.

Unless there is a way to use functions or variables from my ASP class in the HTML or the javascript. How can i do that,if possible?

thanks
Johpje
 
Thanks Izy! I did have a great holiday it was good to get away from work for a while. Yours went well also??

Johpje
Why is that going to be a lot of code? On the event that you want the new window to popup simply do something like this.

dim sb as new stringbuilder()
sb.append(&quot;<script language=javascript>&quot;)
sb.append(&quot;window.open('&quot;)
sb.append(somevariableholdingURL)
sb.append(&quot;')&quot;)
sb.append(&quot;</script>&quot;)

RegisterStartupScript(&quot;Starter&quot;, sb.tostring)
sb = nothing


and thats it. A new window will open to whatever URL is held in somevariableholdingURL. That'l do donkey, that'l do
[bravo] Mark
If you are unsure of forum etiquette check here faq796-2540
 
Zarcom,

The reason why it would be a lot of code, is because i have like al least 30 links that need to be updated with various variables from my ASP Session.

But i think I found another way, but I'll still use the RegisterStartupScript function though.

Thanks to both.
Johpje
 
johpje: Post the final solution. I'm curious. Zarc, spent a good deal of time over the holidays (for fun) funning ArcMap queries (watershed etc...). I want to hook up dot NET with ESRI's IMS system on the web - great combination; but first SQL Server! This year is booked. Thanks.
 
Ok guys,

To be honest, i didn't use any of the above in the final solution. But I learned some new stuff, anyway.

What i did is make a html file that does nothing except for opening a new window with the requested page and redirect itself back to the original page.

I give for example URL .../openPage.htm?redirect=report

<script language=&quot;javascript&quot;>
<!--
report = (here i get the page name out of the URL)
window.open(report + '.html' , '_blank')
window.top.location.href = 'Home.aspx'
-->
</script>

And the first url i can easily construct in the VB part. and redirect with Response.Redirect(URL)

regards
Johpje
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top