How to know in the code behind if the window has been open from another window

 Hi

I want to know in the code behind (server side) if the page has been open from another window. In the client side I can check, in a javascript function, if the window.opener is null or not, but how can I know this in the code behind. Is it possible?

Thanks,

Luis Miguel 

-1
lmmolinero
10/12/2007 8:21:29 PM
asp.net.web-forms 93655 articles. 3 followers. Follow

5 Replies
898 Views

Similar Articles

[PageSpeed] 41

 I think your best bet might be to use a HiddenField, and populate that HiddenField with the javascript window.opener value.

For example:

 <%@ Page Language="C#" AutoEventWireup="true"  CodeFile="Default.aspx.cs" Inherits="_Default" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
    <title>Untitled Page</title>
</head>
<script type="text/javascript">
    function testWindow()
    {
        hiddenField = document.getElementById("hiddenField");
        hiddenField.value = window.opener;
    }
    
</script>
<body>
    <form id="form1" runat="server" onsubmit="testWindow();">
    <div>
    
    <input type="submit" value="Submit" />
    <br />
    <a href="Default.aspx" target="_blank">Open New Window</a>
    <asp:hiddenfield id="hiddenField" runat="server" />         
    </div>
    </form>
</body>
</html>

 

and in the codebehind:

    protected void Page_Load(object sender, EventArgs e)
    {
        Response.Write(string.Format("HiddenField value: {0}<br />", hiddenField.Value));

    }

You can play with that, and see how it goes!

 

 

-1
jason
10/12/2007 9:15:10 PM

Thanks for quick answer.

But this isn’t the solution for the question I posted, because as I said of course I know how to refer to de oponer window in the client side, using window.opener, but the problem is that I want to know it before the page renders, in the server side, if the page has been opened by another window, in order to change some properties of different controls. So I need to know if it is client window before any javascript executes.

 Anyway thanks for your quick answer.

 Luis Miguel

1
lmmolinero
10/13/2007 7:51:08 AM

 What about using something like:

Request.UrlReferrer

If you look at that when you open a window from scratch, it's null....and if it's a link from another aspx page, it has the URL? 

1
jason
10/15/2007 9:28:44 PM

Thanks Jason. You are right, that is the path to the right solution. I use a navigation menu in the main window, so the Request.UrlReferrer is never null, but the answer is in the Request.UrlReferrer.AbsolutePath value, because there I have the information about the opener. Problem solved!

Best regards

Luis Miguel

1
lmmolinero
10/16/2007 10:27:01 AM

 Glad I could help!

-1
jason
10/16/2007 7:09:30 PM
Reply:

Similar Artilces:

how to change these windows form code to web form code?
hi, i'm a beginner of c#,i want to know how to change these windows form code to web form code //////////// private void buttonSign_Click( object sender, System.EventArgs e) { //get original message as byte array byte[] messagebytes = Encoding.UTF8.GetBytes( textOriginalMessage.Text); //create digest of original message using SHA1 SHA1 sha1 = new SHA1CryptoServiceProvider(); byte[] hashbytes = sha1.ComputeHash(messagebytes); //display hash bytes in hex format StringBuilder sb = new StringBuilder(); for (...

open a popup window from.net code behind
Hi I am trying to open a new window from a button in my aspx side. This works, but I have to push the button 2 times before it open. Any idea? Public Shared Sub OpenPopUp(ByVal opener As System.Web.UI.WebControls.WebControl, ByVal PagePath As String) Dim clientScript As String 'Building the client script- window.open clientScript = "window.open('" & PagePath & "')" 'register the script to the clientside click event of the opener control opener.Attributes.Add("onClick", clientScript) End Sub Sub Button1_Click(sender As...

how to open popup window through javascript in code behind( popup window should be aligned center)
I want to use javascript in code behind to open popup window. I have Datalist inside which there is linkbutton. On click of linkbutton open popup window through javascript & that pop up window should be aligned centraly.Regards,Mahesh--------------------click "Mark as Answer" on the post that helps you. Friend, Try this sample . <html xmlns="http://www.w3.org/1999/xhtml" ><head runat="server">    <title>Untitled Page</title>        <style>    .blue{ bac...

window.open and window.opener
Sorry for a really dumb post. I am not a scripting person... I find the whole thing a bit strange really with losely coupled types ect...Anyway, I am putting together a ASP.NET v2 application. One of the pages I am planning on implementing a link to open a pop-up window. In this popup window, the user will select the location of somthing, the window close and the value returned back to one of the parent browsers controls. I know this is not rocket science and I have done endless searches to try and find the answer. I am loading up the page and passing in the ClientID of the control I wish to...

windows forms in vb .net into web forms
we are creating a database driven website as part of our project. currently we have forms connecting to the database created in visual basic. these windows forms we need to convert into web forms which are asp .net compatible. can u give me an answer or show me a way. Hi, because of the difference in nature between web and win applications you'll need to reimplement at least the UI part. If you have a multitiered application in which the busines logic and data access are in different parts/assemblies you can reuse them. Grz, Kris.Read my blog. Handy Firefox plugins for web developers.Wor...

V 3.6 Open New browser window; and window loads behind main window
Name: R Novak Product: Firefox Summary: V 3.6 Open New browser window; and window loads behind main window Comments: I have tested this on Mac: Firefox 3.5.7, Safari, and PC Explorer & Firefox, and this does not happen on any of these other browsers. On a site with a javascript new window (open on mousedown) the new window appears very quickly .2 secs, then s hidden behind parent (main or previous) window. Please fix! Browser Details: Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10_6_2; en-us) AppleWebKit/531.21.8 (KHTML, like Gecko) Version/4.0.4 Safari/531.21.10 From...

how can I use window.opener but with window.showModalDialog instead of window.open
Hi, I tried the code bellow that I found in  :  4guysfromrolla site:the code displays a source page, whn I click on the Calendar <a href />  link  i get a calendar displayed on a target page. when I select a date, the calendar page closes and populates the textbox txtDate with the chosen date. Here is the code of the 2 pages and my question is down bellow:a source page called frmCalendar.aspx has this:<form name="frmCalendar">   <input name="txtDate" type="text" />   <a href=&q...

How to use window.dialogarguments properties to get the information passed in window.showmodaldialog in the code behind of the modal window page
How to use window.dialogarguments properties to get the information passed in window.showmodaldialog in the code behind of the modal window page Hi ashutosh, Here is an article that explains the use of the window.dialogArguments method. In the article is even an example that combines that property with the window.showModalDialog method. The article: http://msdn2.microsoft.com/en-us/library/ms533723.aspx Caution: You have to remember that those methods of the window class are case sensitive. window.showmodaldialog is not the same as window.showModalDialog ! Hope this helps!WimPlease re...

How to use window.dialogarguments properties to get the information passed in window.showmodaldialog in the code behind of the modal window page
How to use window.dialogarguments properties to get the information passed in window.showmodaldialog in the code behind of the modal window pagelaks See if this helps: http://msdn2.microsoft.com/en-us/library/ms533723(VS.85).aspxMark replies as answers if they helped you solve the problem. I saw that..But i want to use it in my code behind.    laks window.dialogArguements is available in client-side JavaScript only.Mark replies as answers if they helped you solve the problem. Any option to have the same functionality of showModalDialog of javascript in asp.net?....

How to call window form from windows servcie in .net
Hi    I created a windows Service and i did following steps.>>protected override void OnStart(string[] args) { // TODO: Add code here to start your service.   System.Windows.Application.Run();Form1 frm = new Form1(); frm.Show(); }   I add the service installer and to start service i opened a command prompt then i typed installutil path/serviceproj.exe. And i started the service from Mycomputer->Manage. But windows service is not showing the form.Everyone is telling windows service not support UI.Its a background thing. So Form is not showing My ques...

Open a new window with window.open()
Hi, =20 in our web application, we try to open a popup-window with window.open(). But instead of opening a new window, a new tab is opened. =20 In the SeaMonkey preferences, we configured it, to open new links in a new tab. With firefox, we had the same preferences, but when window.open() was called, a new window was opened.=20 How can we configure SeaMonkey, so that it has the Firefox behavior when calling window.open() ? =20 Thanks in advance. =20 =20 =20 Artur Zeiler schrieb: > Hi, > > in our web application, we try to open a popup-window wi...

opening new window other than window.open
is there any other way of opening a new window... aside from window.open? window.open has a memory leak so i want to prevent using it as much as possible.Alvin ShihSoftware DeveloperMCP MCTS MCPD Hi window.showmodaldialog() but supports only IE....   Regards Suresh Kumar Goudampally Why dont you avoid pop up windows all together and use an iframe that is positioned over the content? Eric Pascarello.com | Twitter epascarello | LinkedIn Hi,Try Target="_blank" N.P.SenthilSoftware Engineer  Link buttons targer property is set to "_blank"...

maximize a window opened by window.open()
hi I want to allow the user to maximize the window opend by window.open() method sued in a ajax update panel ScriptManager.RegisterClientScriptBlock(this.UpdatePanel1, this.UpdatePanel1.GetType(), "NewClientScript", "window.open('help.aspx?','Report', 'width=500,height=400 ,top=210,left=505, scrollbars=yes');", true); Just have a look for this link it will give you all details in window.open() http://www.javascript-coder.com/window-popup/javascript-window-open.phtml   ...

window.open to open very small window
Hi, in Loggedoutmsg.aspx i am just writing- "YOU HAVE LOGGED OUT"newwin=window.open('Loggedoutmsg.aspx','Congrats',"location=0,status=0,scrollbars=0,width=300,height=1");  I want to open window just to show this line. But the window which gets opened by above code has hight more than necessary. Even when i specified height=1,its size not decreasing to show just one line .How can i do this? Please Mark the post as "ANSWER" if it helps you Answered here: http://forums.asp.net/t/1308177.aspx NC...   Heres something fro...

Web resources about - How to know in the code behind if the window has been open from another window - asp.net.web-forms

Cruz Offers Apology to New Yorkers… ‘Who Have Been Let Down by Liberal Politicians’
After his repeated swipes on “New York values,” Ted Cruz yesterday offered an apology to New Yorkers… “who have been let down by liberal politicians.” ...

4 Jihadis and 23 Civilians Dead After Al Qaeda Gunmen Storm Luxury Burkina Faso Hotel
Overnight on Friday, gunmen linked to Al Qaeda seized a luxury hotel, popular with Westerners, in the capital of Burkina Faso. By Saturday morning, ...

Taiwan elects new nationalist president, threatening China relations
It’s getting hard to keep track of all the international news this week, what with so much of the world being on fire and all, but there was ...

'Prison Break' Revival Ordered Straight to Series
It’s really official – Prison Break is coming back. While Fox ordered a pilot episode back in the summer, the network just announced that the ...

Marco Rubio Condemns Prisoner Swap for Post Journalist
(Johnston, Iowa) — Florida Sen. Marco Rubio said Saturday morning he was not aware of the specifics of the release of four Americans held prisoner ...

Recommended Reading: The brilliance of David Bowie
'Heroes,' Heavenly Bodies and David Bowie's Untouchable Brilliance Bomani Jones, Playboy I've followed the work of ESPN's Bomani Jones long enough ...

Bill Maher Petitions President Obama To Appear On ‘Real Time With Bill Maher’ – And Thousands Of Viewers ...
Bill Maher fans (nearly 30,000 and counting) have answered the talk-show host’s call to arms — or, more accurately, call to fingers — by typing ...

Tennessee Powerball winners plan to keep working
ABC News Tennessee Powerball winners plan to keep working WTVA NASHVILLE, Tenn. (AP) — The latest on a Tennessee couple that says they won ...

Box Office: ‘Ride Along 2’ Shoots for $38 Million, Topping ‘The Revenant,’ ‘Star Wars’
Kevin Hart and Ice Cube’s cop sequel “Ride Along 2” will top the box office over the Martin Luther King, Jr., holiday weekend, with studio estimates ...

Wal-Mart to close 154 stores in the US
Wal-Mart is closing 154 stores in the U.S. and another big chunk in its challenging Brazilian market.

Resources last updated: 1/16/2016 5:26:40 PM