Click here to Skip to main content
13,345,867 members (51,459 online)
Click here to Skip to main content
Add your own
alternative version


9 bookmarked
Posted 26 May 2014

Refresh a Frame from Another Frame in ASP.NET

, 26 May 2014
Rate this:
Please Sign up or sign in to vote.
In this tip, we will create a small project to give demo how we can refresh a Frame from another Frame in ASP.NET.


HTML frames (not supported in HTML5) allow the user to view multiple pages on the same window. For example, within the same window, one frame might display a static banner, a second a navigation menu, and a third the main document that can be scrolled through or replaced by navigating in the second frame.

Please feel free to share your comments / suggestions and rate this tip. :)


In this tip, we'll see how we can refresh one frame from another frame on a single window.

Let's have a simple example with two web pages - Page1.aspx, Page2.aspx and an HTML page - HtmlPage1.html

  • Page1.aspx - will contain a hyperlink which will cause refresh of Page2.aspx
  • Page2.aspx - will contain a label control to display the Page Refreshed time
  • HtmlPage1.html - will contain two <frame> controls pointing to both the web pages, i.e., Page1.aspx and Page2.aspx

Using the Code

Let's try this example by creating a new project called FramesDemo:

Add a new Web Form - Page1.aspx

An anchor tag <a href="/KB/aspnet/Page2.aspx" target="frame2">Click to refresh Page 2</a> is added. Here, target="frame2" will make sure that Page2.aspx is loaded in "frame2".

<!DOCTYPE html>
<html xmlns="">
<head runat="server">
    <form id="form1" runat="server">
            <h1>Page 1</h1>
            <a href="Page2.aspx" target="frame2">Click to refresh Page 2</a>

Let's add another page - Page2.aspx

Here, we have added a Label control to display the current Date-Time.

<!DOCTYPE html>
<html xmlns="">
<head runat="server">
    <form id="form1" runat="server">
            <h1>Page 2</h1>
            Page Refreshed at: 
            <asp:Label ID="lblCurrentTime" runat="server" 


We want to display the current Date-Time on every refresh of this page. The following code will make sure that current Date-Time is set to the Label control:


using System;
namespace Frames_Demo
    public partial class Page2 : System.Web.UI.Page
        protected void Page_Load(object sender, EventArgs e)
            //Display current date time on refresh of this page
            lblCurrentTime.Text = DateTime.Now.ToString();

Now, we will add a container HTML page with two frames pointing to the web pages, i.e., Page1.aspx and Page2.aspx.

Let's add a new HTML file - HtmlPage1.html (keep the default name):

Modify the page to add a <frameset> control with two <frame> controls. Make sure that name="frame2" is set for the second <frame> control so that it can be referred by the Page1.aspx:

<!DOCTYPE html>
<html xmlns="">
<frameset cols="50%,50%">
    <frame src="Page1.aspx">
    <frame src="Page2.aspx" name="frame2">

Set HtmlPage1.html as Start Page and hit F5 to run the web site.

Click on the hyperlink - "Click to refresh Page 2" on Page 1 and see how the Page Refreshed time is changing on Page 2.

Hope you like this tip.

Happy coding! :)


  • 26th May, 2014: Initial version


This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


About the Author

India India
My name is Debabrata Das, also known as DD. I started working as a FoxPro 2.6 developer then gradually moved towards VB6, Classic ASP, COM, DCOM. Presently in love with ASP.NET and C#.

I believe in "the best way to learn is to teach". Passionate about finding a more efficient solution of any given problem.

You may also be interested in...

Comments and Discussions

Questionframe Pin
satyashri2-Jul-15 5:00
membersatyashri2-Jul-15 5:00 
GeneralMy vote of 5 Pin
Carsten V2.026-May-14 5:43
memberCarsten V2.026-May-14 5:43 
GeneralRe: My vote of 5 Pin
Debabrata_Das26-May-14 6:45
memberDebabrata_Das26-May-14 6:45 
GeneralExcellent article Pin
suhel_khan26-May-14 4:17
membersuhel_khan26-May-14 4:17 
GeneralRe: Excellent article Pin
Debabrata_Das26-May-14 4:18
memberDebabrata_Das26-May-14 4:18 
GeneralMy vote of 4 Pin
awadh.t26-May-14 3:56
memberawadh.t26-May-14 3:56 
GeneralRe: My vote of 4 Pin
Debabrata_Das26-May-14 4:14
memberDebabrata_Das26-May-14 4:14 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

Permalink | Advertise | Privacy | Terms of Use | Mobile
Web04 | 2.8.180111.1 | Last Updated 26 May 2014
Article Copyright 2014 by Debabrata_Das
Everything else Copyright © CodeProject, 1999-2018
Layout: fixed | fluid