Click here to Skip to main content
15,299,443 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
I am trying to redirect to different content page through my master page but i don't want to refresh my master page.
As our master page is nothing but an content page only but i don't want to refresh master page content.
Ant technology in asp.net so that i can achieve it.

Thanks
Posted
v2

try to use iframe instead masterpage.. :)
Check out this example

HTML
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
    <style>
        .iframrStyle
        {
            height: 1000px;
            width: 100%;
            border: none;
        }
    </style>
    <script>
        function SetPageURL(PageURL) {

            document.getElementById("MyFrame").src = PageURL; //iFrame source set dynamically
        }

    </script>
</head>
<body>
    <form id="form1" runat="server">
        <div class="Header">
            <%--Menu--%>
            <nav>
                <ul>
                    <li  önclick="SetPageURL('Home.aspx')">Home</li>
                    <li  önclick="SetPageURL('About.aspx')">About</li>
                    <li  önclick="SetPageURL('Contact.aspx')">Contact Us</li>

                </ul>

            </nav>

        </div>
        <div class="MainBody">
            <%--iframe--%>
            <iframe id="MyFrame" src="Home.aspx" class="iframrStyle">

            </iframe>

        </div>
        <%--footer--%>
        <div class="Footer">
        </div>

    </form>
</body>
</html>



You can call child page javascript function from parent page in this way.

JavaScript
document.getElementById('MyFrame').contentWindow.FuncName(); //FuncName() is a function of child page.


You can call patent page javascript function from child page in this way.

JavaScript
top.FuncName(); //FuncName() is a function of Parent page.
   
v3
Comments
Member 10202727 14-Jun-14 7:08am
   
thanx for it but i don't want to use IFrame and user controls
is it something like asyncpostback ?
Hello friend, you can use Ajax UpdatePanel control in Master Page to refresh the content page only. Try the following code:

MasterPage.aspx:
XML
<asp:ScriptManager ID="ScriptManager1" runat="server"></asp:ScriptManager>
<h1>Master Page</h1>
<asp:Label ID="Label1" runat="server" Text="Label"></asp:Label>
<div>
    <hr />
    <asp:UpdatePanel ID="UpdatePanel1" runat="server">
        <ContentTemplate>
            <asp:ContentPlaceHolder ID="ContentPlaceHolder1" runat="server">
            </asp:ContentPlaceHolder>
        </ContentTemplate>
    </asp:UpdatePanel>
</div>

MasterPage.aspx.cs:
C#
protected void Page_Load(object sender, EventArgs e)
{
    Label1.Text = DateTime.Now.ToString();
}

ContentPage.aspx:
XML
<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" runat="server">
    <asp:Button ID="Button1" runat="server" Text="Button" OnClick="Button1_Click" />
    <asp:Label ID="Label1" runat="server" Text="Label"></asp:Label>
</asp:Content>

ContentPage.aspx.cs:
C#
protected void Button1_Click(object sender, EventArgs e)
{
    Label1.Text = DateTime.Now.ToString();
}

In this way the content page DateTime will be refreshed in every hit of the button, but DateTime on MasterPage will remain unchanged.

Let me know if you have any further query.

- DD
   
Comments
Nirav Prabtani 14-Jun-14 16:24pm
   
For that we have to use Form tag with runat server in in master page and content page as well so is it possible???
sri44 24-Jul-19 3:29am
   
Update Panel will not work in the master page for content placeholder tag.Need to put update panel in the content page.
Debabrata_Das 24-Jul-19 7:29am
   
sri44 Have you tried the solution that I shared? If not, I would encourage you to try once before getting into any conclusion.

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



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900