|
| Response.Redirect to a new browser page |
|
|
|
|
| Messages |
|
Related Types |
This message was discovered on microsoft.public.dotnet.academic.
| Fred Nelson |
| GOOD ANSWER |
Hi:
I am working on a VB.NET application in which I need to open a new browser and direct users to it in the event they click on a button or image.
I want to keep my page open so they will return to it when they are done.
For example:
on click response.redirect("website",target=_blank) end
If anyone can point me in the right direction I would greatly appreciate it!
Thanks,
Fred
|
|
|
| |
|
|
| |
| |
| Ray D. |
| GOOD ANSWER |
It sounds like you should look at opening a new window via client script. The window.open() method will allow you to open a new window (with any URL you specify) and keep the existing page open.
-- Ray D. (remove NOSPAM. from my e-mail address for a direct reply)
"Fred Nelson" <Click here to reveal e-mail address> wrote in message news:Click here to reveal e-mail address... [Original message clipped]
|
|
|
| |
|
|
| |
| |
| Fred Nelson |
| GOOD ANSWER |
Thanks Ray:
It looks like the window.open() method is exactly what I'm looking for. I can't figure out how to call it from within a VB.NET web application - I assume that its related to the namespaces which is something that is still way beyond me.
I'm assuming that I need something like:
includes system.windows ??? dim objNewWin as new ??? objNewWin = window.open("Sample.htm","height=200,width=400,status=yes,toolbar=no,menubar =no,location=no")
Am I close or totally lost? I would appreciate your help!
Thanks,
Fred
"Ray D." <Click here to reveal e-mail address> wrote in message news:#Click here to reveal e-mail address... [Original message clipped]
|
|
|
| |
|
|
| |
| |
| Wayne Bisson |
| GOOD ANSWER |
Hi Fred,
The window.open() method is a client side function which means that you need to include the call within the ASPX page. The way to implement this when the user clicks on an element in the page is to put the call to the window.open() method in the onlcick attribute. For example, to redirect to a webpage when the user clicks on an image:
<img src="sourceurl" onclick="window.open('website', '_blank');">
- Wayne
"Fred Nelson" <Click here to reveal e-mail address> wrote in message news:Click here to reveal e-mail address... [Original message clipped]
|
|
|
| |
|
|
| |
| |
| Fred Nelson |
| GOOD ANSWER |
Wayne:
Thank you very much for explaining this to me - now it makes sense to me on the client side.
Is there a way to implement this on the server side - my application needs to track the clicks that I get on various ads, record them in a database, and then open a new window and send the user on their way. Everything that I need is working now with the only exception being that I'm using response.redirect(desturl) and I am not able to open a new window so that mine stays open in the background.
Is there a way to accomplish this?
Thanks very much again,
Fred
"Wayne Bisson" <Click here to reveal e-mail address> wrote in message news:Click here to reveal e-mail address... [Original message clipped]
|
|
|
| |
|
|
| |
| |
| Wayne Bisson |
| GOOD ANSWER |
Fred,
Have a look at the AdRotator control: http://msdn.microsoft.com/library/default.asp?url=/library/en-us/mwdesign/ht ml/mwconintroductiontotheadrotatorcontrol.asp
It is a server side control that changes the ad that is displayed to the user every time the page is refreshed. In it's simplest form you can provide it with an xml file that specifies all the properties of and e.g. image url, destination url etc. It also allows you to weight the ad priority accordingly so that some ads appear more often than others. There isn't anyway of capturing the click on the ad with server side code and then opening up the new window etc. because the ad control renders with the client side code in order to do this. I'm not sure if it would provide an adequate solution to your problem, but it's always worth knowing about :-)
If not, have a look at the ImageButton control: http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpgenref/ht ml/cpconimagebuttonwebcontrol.asp
It's simply just a image control that allows you to handle the click event in server side code. The main difference here is that you will need to write your own code to assign a random url to the ImageUrl property of the control, but otherwise it should solve your problem. When you handle the Click event of the control you can check to see what the current ImageUrl is and then increment the click count for that advert.
Hope one of these solutions help
- Wayne
"Fred Nelson" <Click here to reveal e-mail address> wrote in message news:Click here to reveal e-mail address... [Original message clipped]
|
|
|
| |
|
|
| |
| |
| Fred Nelson |
| GOOD ANSWER |
Wayne:
Thanks again - you have been very helpful!
I already have everything working that I need in terms of deciding what page I'm going to route the user to. The image button is what I have used to show the user what to click on. I'm only missing one thing and that is how to open a new window on the server side.
Everything that I need is working with the single exception being that I can't find a way to open a new browser - all I am able to do is to change the URL of the current browser.
For example what I need is:
image1_onclick() incrementdatacounter() response.redirect.to_brand_new_window(wwwdesturl)
what I have is: incrementdatacounter() response.redirect(wwwdesturl)
If you know of how to open a new browser from the server side then it would make my day!
Thanks again,
Fred
"Wayne Bisson" <Click here to reveal e-mail address> wrote in message news:Click here to reveal e-mail address... [Original message clipped]
|
|
|
| |
|
|
| |
| |
| Wayne Bisson |
| GOOD ANSWER |
It's probably a bit of a hack, but the only way that I can think of doing it at the moment is:
1) Define a hidden HTML element on the page, such as :
<input id="hiddenURL" type="hidden" runat="server">
2) Now add the following javascript block after the definition of the html element:
<script language="javascript"> if (hiddenURL.value != "") window.open(hiddenURL.value, "_blank"); </script>
3) Finally make sure you assign a value to the hidden element in the click event of the imagebutton.
hiddenURL.value = "http://www.google.com";
It should then open the new window when the page loads.
- Wayne
"Fred Nelson" <Click here to reveal e-mail address> wrote in message news:#Click here to reveal e-mail address... [Original message clipped]
|
|
|
| |
|
|
| |
| |
| Wayne Bisson |
| GOOD ANSWER |
Sorry Fred, there's a couple of points that I realised that I forget from the previous mail:
1) I don't think that it is possible to open a new window from server-side code. It wouldn't make sense to be able to trigger it because it needs to be executed on the client machine. All we are sending to the client machine is an HTML stream, so we need to make sure that the client-side code is run.
2) Obviously change the google url to whatever url is appropriate for the current advert
3) I actuallly only noticed after I sent the code that it has a line missing. Use the following instead:
<script language="javascript"> if (hiddenURL.value != "") window.open(hiddenURL.value, "_blank"); hiddenURL.value = ""; </script>
The reason is because if you don't set the value back to blank, then it will cause a bnew window every time it refreshes after that... even if it was a totally different control that caused the post-back.
Sorry about the dual reply
- Wayne
"Wayne Bisson" <Click here to reveal e-mail address> wrote in message news:3e5cf4d7$Click here to reveal e-mail address... > It's probably a bit of a hack, but the only way that I can think of doing it [Original message clipped]
|
|
|
| |
|
|
| |
| |
| Ray D. |
| GOOD ANSWER |
You can also use the .Attributes collection of a server control to register a client-side event. For instance, if you insert a client side function named openMyWindow(), you can set that to be your onclick event for the server control like this (assuming your server control is named ImageButton1):
ImageButton1.Attributes.Add("onclick", "openMyWindow();");
The above example is in C#, but the VB.NET code would be pretty much the same (minus the semicolon), I think.
Check http://msdn.microsoft.com/library/default.asp?url=/library/en-us/vbcon/html/ vbconWebFormsEventModel.asp for more info on using client code with server controls.
-- Ray D. (remove NOSPAM. from my e-mail address for a direct reply)
"Wayne Bisson" <Click here to reveal e-mail address> wrote in message news:Click here to reveal e-mail address... [Original message clipped]
|
|
|
| |
|
|
| |
|
|
|
|
|
|
|
|
|
| |
| dennis peter |
| GOOD ANSWER |
I'm not sure wether you'r still looking for this solution. I've been pondering this question my self and I think I've got a solution for you.
Based on Wayne's idea, instead of putting the javascript in the html, why don't you dynamically do insert the javascript on the server side like this
Response.Write("<script language='javascript'>function PopUp(PopUpURL){window.open(PopUpURL, '_blank');} PopUp('www.google.com')</script>");
When the user clicks on your server controls, the server-side will dynamically generate a client script using the Response.Write method. And the good thing is, you can use all the standard client scripting here and it would work just fine.
Hope this will solve your problem.
-------------------------------- From: Dennis The Manace
|
|
|
| |
|
|
| |
|
|
|
|
|
|
|
|
BootFX
Reliable and powerful .NET application framework. |
|
|
|
|
|
|