I have a asp.net page (redaktionsplan.aspx), which contains a iframe, which also represent a asp.net-page:
<iframe src='test.aspx' height="1000px" width="700px" frameborder="0">
test.aspx contains a control (label1). Now, I want in the OnLoad-Event of the label1 (which is on test.aspx) (in CodeBehind of the label1) access a control which is on redaktionsplan.aspx.
How is this possible?
You cannot access controls of another page on the server.
The two pages are requested by the browser with two separate HTTP GET requests: the first one for redaktionsplan.aspx, then when that page is rendered in the browser, another request is made for test.aspx.
So the code-behind on these two pages runs sequentially (not at the same time) and in the context of two different requests.
If you need to exchange data between two pages, then you can for example:
let the first page store the data in the session, so that during the second request you can access it
implement the functionality on the client side, using javascript
Related
I received a new requirement today: For our product page, they want a completely different layout to be used based on the product type.
For example, say we sell buckets. Currently, all buckets use the exact same page layout. But now, they want wooden buckets to use the current layout, and plastic buckets to use a completely different layout. However, they want the URLs to stay the same (e.g., domain.com/bucket/1), so I can't just forward plastic buckets to a new page.
The current page structure is as follows:
CurrentMasterPage.master > CurrentProductPage.aspx > Several UserControls
The new layout requires new pages (i.e., none of the current ones are reused):
NewMasterPage.master > NewProductPage.aspx > Several UserControls
My first thought was to take all of the markup and code from CurrentProductPage.aspx and put it into a UserControl, then create a second UserControl for the new layout (NewProductPage.aspx), and have CurrentProductPage.aspx dynamically load the appropriate UserControl based on the product type, however, this doesn't work because the new layout requires a new MasterPage, and I can't reference a MasterPage from a UserControl.
Then, I thought about using URL Rewriting, but I don't think it's possible to have the same URL load two different pages.
Is there any way to accomplish this?
Why not use a 100% server side re-direct?
When you use response.Redirect("some different page"). Then the client side browser is sent a whole new copy of that page, and the URL will be updated.
However, the server side can write any page it wants to. The client side will not even know the server decided to dish out a different page for the given URL.
So, you could have a page with fake tabs as buttons. When the user hits a button, the browser round trip starts (for the given URL). But on server side, you can then dish out a different page for that URL.
So, in place of this classic "round trip", you can use:
Server.TransferRequest("MyotherWebPage")
So, for the given URL, before the current page (based on given URL) is sent down back to the browser, the above will simply pump out a different page. The current page will never make it back down to the browser.
In fact for a rich page with lots of buttons and features, you can change the page displayed. So in on-load - simply in place of a "response.Redirect", use a server.Transfer. The current page never makes it to the client - the one you dish out where. Because the client side has zero clue about what the web server decides to dish out - it will also have zero clue that a different page was send back to the client.
Try the above with a test page.
On page A, behind a standard button, jump to web page B
eg:
Response.Recdirect("MyPageB.aspx")
Note the URL change - classic round trip.
Now, do this with the button:
Server.Redirect("MyPageB.aspx")
In this case, no full round trip occurs. The server transfers directly to the new page and sends that out. (and note how your URL does NOT change).
You can change the Master Page on PreInit on the Page using a Master. This is possible because a Master is basically the same as a User Control and is loaded AFTER the page's code behind.
protected void Page_PreInit(object sender, EventArgs e)
{
if (NewProductPage)
{
MasterPageFile = "~/NewMasterPage.master";
}
}
I want to show a web page within another web web in asp.net. I have a page named home.aspx and a page name add.aspx how can i do this.
if you just want to load contenct than make use of jquery ajax function or noraml ajax to load data in you page
Example
$("#result").load("AjaxPages/Page.aspx", function () {
alert("Page.html has been loaded successfully!")
});
Use iframes. Pleace for example this code inside the homep.aspx. This is only the idea, find how to show it with out border and with out scrool bars, and also how to fit it in place.
<iframe src="add.aspx"></iframe>
http://www.w3schools.com/tags/tag_iframe.asp
http://htmlhelp.com/reference/html40/special/iframe.html
ajax and iframe
Use ajax if you have some informations only to show. Use iframe if you also need independend post backs that enters data.
ajax is better if you care to have only one page, not working with out javascript, and maybe you need to add more ajax to make more thinks with the data that you get.
iframe is fast, but 'dirty' because is not seo friendly, a user can open content from iframe alone, etc.
So, I have a page that looks like the following:
alt text http://img704.imageshack.us/img704/5973/croppercapture3.png
This is my basic messaging inbox. I have 2 pages right now, Inbox and Sent (there will eventually be others). These both share the same View, and just have 2 different actions to populate the appropriate data.
The elements on the right-hand side (the message list) is a partial view which has its data populated based on my two controller actions Inbox(int? page) and Sent(int? Page).
So, I have one view "MessageView" and one partial view "MessageList" shared between Inbox/Sent.
However, I now have to get those arrow buttons ("<" ">") working using Ajax. I know how to use jQueries ajax calls well enough, and I know how to render the result of the action call (which returns a partial view).
The problem comes from the fact that the javascript that makes these pagination ajax calls needs to know two things:
What the current page is (whether it be /messages/inbox or /messages/sent)
What the current page is (specified in the query string, ie /messages/inbox?page=2).
Without knowing which page I'm on (Inbox or Sent), it wont know which url to make the ajax call on. Should it make the postback to /messages/inbox or to /messages/sent?
If I wasn't making these messages load with Ajax it would be as simple as loading the appropriate url into the link tags for the "<" and the ">" buttons. But I can't, because part of my requirements states that it must load the messages below without visibly refreshing to a new page.
In JavaScript you can check window.location.pathname to see the pathname section of the current’s page’s URL.
window.location.search gives you the query string.
When the user clicks the Inbox or Sent buttons, you need to rewrite the URLs in your arrows so that they point to the right place.
I have an asp.net content page which is used inside of a master page (with header, menu and some links). I would like to reuse it in a different context without the master page (to not display the header and menu there), or with an empty master page if this is somehow possible. I don't want to violate DRY principle by taking the whole page and creating a standalone clone of it for obvious reasons. Is this somehow possible ?
Yes, you can set the master page dynamically in the content pages Page_PreInit method:
private void Page_PreInit(object sender, EventArgs e)
{
this.MasterPageFile = "MyMasterPage.master"
}
Set up some logic to dynamically choose which master page filename to pass in, and you are now sharing one content page with many master pages.
How about wrapping-up the shared content in a user control?
A user control is a kind of composite
control that works much like an
ASP.NET Web page—you can add existing
Web server controls and markup to a
user control, and define properties
and methods for the control. You can
then embed them in ASP.NET Web pages,
where they act as a unit.
From what I've already read this appears to be impossible, but I wanted to see if anyone out there has a secret trick up their sleeve or at least a definitive "no".
Supposedly a master page is really just a control for a content page to use, not actually the "master" of a content page. If I wanted to go from one content page, to another content page with the same master page, I would just say
Response.Redirect("PageB.aspx");
But this would immediately cause a postback, flickering the page, which is the crappy pre-ajax way of doing things.
In this current project, I'm trying to see if I could figure out how to change the current content page of a ContentPlaceHolder in the master page asynchronously, when a button is clicked on the master page.
Is this possible, if so how?
I don't know if you can between pages (.aspx) but it can definitely be done using UserControls.
ASP.Net pages each have their own URL so what you're trying to do is to go from one URL to another without any postback, that's just not how it's supposed to work.
Using user controls (.ascx):
Create a page that uses the MasterPage and use something like this in the content
<ajax:UpdatePanel ...>
<ContentTemplate>
<asp:PlaceHolder ...>
</ContentTemplate>
</ajax:UpdatePanel>
Search for UpdatePanel and tweak its settings to do what you want, then learn how to swap user controls in a placeholder.
No, you cannot because a master page is actually a control rendered on a particular aspx page, rather than actually containing the aspx page as it deceptively appears to be programmatically and in design view.
More Info:
You could however use a variety of other controls to simulate this effect. The asp:MultiView control is one example, each "page" could be made in a single view and placed in an update panel, thus allowing it to be switched asynchronously. Alternatively you could define each page in a separate user control and put those in an update panel, asynchronously switching the visible property on those controls as needed.
There are really a lot of different ways to achieve an effect similar to changing the master page's content placeholder.