I have a Main.aspx page and a Sub.aspx page.
The Sub.aspx page resides in my Main.aspx page via IFrame. So the IFrame contains / loads the Sub.aspx
In another Third.aspx completely unrelated I've got some code that needs to redirect back to Main.aspx but then there are some querystrings that need to be passed to Sub.aspx (or put antoher way my Sub.aspx needs to get those values from the Main.aspx).
My Sub.aspx will check for that querystring flag and if set, run x JS scripts.
Maybe pass the QueryString values to Main and, in its Page_Load, include them in the src for the iframe? You can use the iframe like a server control to do this.
Related
I'm using ASPX web pages (WebPage1.aspx) and have an HTML iFrame defined in this page. I dynamically define the iFrame src (via code behind) when my ASPX web page loads ... all good so far.
The web page that gets loaded into my iFrame supports a "ReturnURL" that I've defined when I set the src for the iFrame. Something like:
src = "https://www.someothersite.com/Somewebpage.aspx?ReturnUrl=http://www.mywebsite.com/WebPage2.aspx"
The web page (Somewebpage.aspx) has a "Return" button, the user clicks the Return button and they should get redirected back to the "ReturnURL" I specified (http://www.mywebsite.com/WebPage2.aspx).
What happens is http://www.mywebsite.com/WebPage2.aspx gets displayed in my iFrame on http://www.mywebsite.com/WebPage1.aspx. This IS NOT what I wanted, I wanted to simply be return to http://www.mywebsite.com/WebPage2.aspx.
Is there a solution to this problem within the context of ASPX and code behind?
Cheers, Rob.
Scenario:
I have one main master page say MasterPage1. In that master page I have a splitter. In that splitter there is an iframe. Within that iframe we load another master page say "MasterPage2". In MasterPage2 we load a page on which different User Controls are rendered.
Problem:
Now I want to find a control on MasterPage1 from my User Control loaded on the page in MasterPage2.
Please help....
Problem To your Scenario:
masterpages and content pages are rendered as a single object, thus the page class is able to reference every element found in both the objects(master and content page). When you are rendering an iframe the iframe content is requested by client hence no reference exists. so it is not possible to reference each other on server.
Solution to the problem
From above you must have realized all the problem is the reference , so you will have to hack inti it. the simplest way I can think is to use querystring.
call the iframe page with querystring containing a identifier to the masterpage like mpage=mpage1,mpage=mpage2 etc.
Now in masterpage2 request the querystring to find which masterpage is applied and proceed. This way you will have little relaxaction because masterpage1 content cannot be changed but masterpage2 can be.
Now you will need to work more to what you need. Proceed only if this is the only way to solve the real problem(I think the problem is not masterpage but the solution to the problem that is making you to do these weired things).
Well for that you will have to use javascript and handlers which will render and return the rendered usercontrol. But i seriously say not to use this setup in production and find other alternative by changing your code to use usercontrol instead of iframe.
I set a src attribute of an iframe as a home page, so after login we redirect the user to the home page.
When the user navigates around it is fine, but the problem comes when the user uses the F5 key on the keyboard as a refresh button.
It refreshes the entire page, which kicks them back to the main page (home page which was set as the src in iframe).
So, I have put the last visited page url in a session variable. But a problem occurs when the last visited page url uses the post method. Then just putting the url in the iframe src does not work as the form has method=post.
this is a common post problem, not related to iframe actually. this is the method i use to prevent this issue:
use posted data (store it to database etc.) and immediately redirect to another page before showing anything on screen. if some data needs to be used on the next page, read it from stored place or use either session or get method to pass to the next page.
that way, you won't have any problems with refreshing the page. you can also store the next page's url to the session variable at the posted page.
My aim is to stream a .htm file via Response.WriteFile("Sample.htm"); and then access a specific html element (ex. <a runat="server" id="myAnchor" /> ) from the Response which happened in the Page_PreInit Event.
I tried it already with ((HtmlGenericControl)myAnchor) but it doesn't work. It only works, if the anchor tag is inside the .aspx page.
Is there a possibility to reinitialize the .aspx page after the response.write event happened, so that the anchor tag from the sample.htm file gets indexed like it would be an anchor tag from the .aspx page.
Thanks for your help.
No. Once you write anything directly to the response stream it leaves the web server (where your code is running) and goes directly to the browser. Do not pass 'GO'. Do not collect $200.
Anything in that file is never loaded into your Page class' control tree in the first place, but sent directly to the browser. "reinitialize the .aspx page" wouldn't help you. Instead, to re-use content like this, you need to embed it in a control that can be included on the page or put it in a master page.
I'm working on a page, in which other pages are opened from it in a modal way.
I need to call function exists in opener page to update certain controls in it.
I'm using window.open to open another window but in this case Page.PreviousPage for opened page is null.
I'm using
<%# PreviousPageType VirtualPath="~/PreviousPage.aspx" %>
to refer to Previous Page.
Any suggestions?
FYI: all aspx pages are AJAX-Enabled.
You can't call a method in the code behind of a Page class to update controls in a page that is displayed. The instance of the Page class only exists while the page is rendered, once the page is displayed in the browser, the Page object no longer exists.
The PreviousPage property is used when you make a post from one page to another, but it doesn't contain the Page object that was used to render the page, it contains a recreated Page object that will not be used to render anything at all. You can only use it to read information from the fields based on the information that was posted from it.
If you want to update the opener page you either have to do it on the client side using Javascript (), or reload the page so that the server side code can repopulate it. A combination of them both would be to use AJAX to update the page.
Edit:
You can for example use Javascript to access the opener and change the content of an element:
window.opener.document.getElementById('Info').innerHTML = 'updated';
You can also call a Javascript function in the opener page:
window.opener.doSomething('data');
That which gives you more possibilities, like making an AJAX call to load data from the server.
You can submit the parent page back to the server using javascript. You can use window.opener function in the javascript to access the parent page.