Click here to Skip to main content
15,881,812 members
Please Sign up or sign in to vote.
2.33/5 (2 votes)
See more:
In my project I want to go to Home page from other page using 'responce redirect'. In master page I have the button 'BtnHome' with a click event named as OnClick="BtnHomeClick".
When I use the following code and click the 'Home' button , it says :'The type of page you have requested is not served because it has been explicitly forbidden. The extension '.master' may be incorrect. Please review the URL below and make sure that it is spelled correctly.'
Hereunder I submit the code:

C#
protected void BtnHomeClick(object sender, EventArgs e)
    {
        Response.Redirect("~/MasterPage.master");
    }



XML
<asp:Button ID="BtnHome"  runat = "server" Text='Home' Font-Size="Medium"  PostBackUrl="~/MasterPage.master" OnClick="BtnHomeClick" Font-Bold="true"  ForeColor="White" BackColor="Teal"  CausesValidation="false"
            style=" margin-top:16px; cursor:pointer;  margin-left:225px"   BorderStyle="None" > </asp:Button>
Posted

1 solution

You cant Navigate to a MasterPage. You should consider creating a Home page which serves as a content page of the Master Page and redirect to it.
 
Share this answer
 
Comments
S.Rajendran from Coimbatore 11-Dec-13 23:41pm    
I am haveing the "home' button in master page. If I create a Home page and in that how to redirect to master page.
JoCodes 12-Dec-13 0:00am    
Just use Response.Redirect("Home.aspx"); for the button click event. It will work.
JoCodes 12-Dec-13 0:01am    
The basic idea is MasterPage is not a Page which you can navigate. Its for rendering as part of the Content Page . You can have X number of Content Pages anywhere you can redirect within .
S.Rajendran from Coimbatore 12-Dec-13 0:08am    
I did like this but not working:
My home.page:
<%@ Page Language="C#" MasterPageFile="~/MasterPage.master" AutoEventWireup="true" CodeFile="Home.aspx.cs" Inherits="Home" Title="Untitled Page" %>

<asp:Content ID="Content1" ContentPlaceHolderID="head" Runat="Server">

<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" Runat="Server">


In my masterPage.cs code for Homebutton is:
protected void BtnHomeClick(object sender, EventArgs e)
{
Response.Redirect("Home.aspx");

}
Should I code something in Home.cs. As of now I have not coded anything.
S.Rajendran from Coimbatore 12-Dec-13 0:50am    
Well. It works with the same code after I rebuilt the solution. Thanks.

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