steventnorris
steventnorris

Reputation: 5896

Load another asp.net page into current page

Using ASP.NET with C#, I would like to load the content of another page into my current page.

I have a main div id="maindiv" on one page with a header above it. The header contains clickable links that route to the same url with a get variable like http://www.mainpage.com&page=nextpage. I would like to use the page get variable in a switch case to load from a specified page into maindiv. I can do the switch case bit fine, but how do I load the response from another page?

Upvotes: 0

Views: 25361

Answers (4)

Hassan Boutougha
Hassan Boutougha

Reputation: 3919

a possible solution is

set an iframe like in http://geekswithblogs.net/ranganh/archive/2005/04/25/37635.aspx you will take your query string parameter to set source of iframe

frame1.Attributes["src"] = "http://www.live.com" ;

in code behind

frame1.Attributes["src"] = nextpage ;

Upvotes: 1

jrummell
jrummell

Reputation: 43077

It sounds like you want to keep the same layout (header, navigation, footer, etc) for all of your pages. ASP.NET 2.0 introduced Master Pages, which are basically layout files that allow you to create Content pages that fill in place holders in the layout.

ASP.NET master pages allow you to create a consistent layout for the pages in your application. A single master page defines the look and feel and standard behavior that you want for all of the pages (or a group of pages) in your application. You can then create individual content pages that contain the content you want to display. When users request the content pages, they merge with the master page to produce output that combines the layout of the master page with the content from the content page.

Here's a sample from the MSDN article.

Master Page:

<%@ Master Language="C#" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 
    1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server" >
    <title>Master page title</title>
</head>
<body>
    <form id="form1" runat="server">
        <div><asp:contentplaceholder id="Main" runat="server" /></div>
        <div><asp:contentplaceholder id="Footer" runat="server" /></div>
    </form>
</body>
</html>

Content page:

<% @ Page Language="C#" MasterPageFile="~/Master.master" Title="Content Page 1" %>
<asp:Content ID="Content1" ContentPlaceHolderID="Main" Runat="Server">
    Main content.
</asp:Content>

<asp:Content ID="Content2" ContentPlaceHolderID="Footer" Runat="Server" >
    Footer content.
</asp:content>

Upvotes: 4

Conrad Lotz
Conrad Lotz

Reputation: 8818

This related post might provide a solution to your problem:

How to display an ASPX in another ASPX's DIV dynamically at runtime?

Upvotes: 0

CoderMarkus
CoderMarkus

Reputation: 1118

I would suggest either using Panels and showing based on URL variable or use .ASCX user control files and load those based on URL variable if you need code behind logic.

<asp:Panel ID="pnl1" runat="server" visible="false">
    page 1...
</asp:Panel>

<asp:Panel ID="pnl2" runat="server" visible="false">
    page 2...
</asp:Panel>

Upvotes: 0

Related Questions