Get the page name example in c#

August 17, 2015 0 Comments

In this article i will learn how to get the page name in If you are using visual studio 2005 to 2010 then url show page name with extension. But if you are using vs2012 to vs2015 then do not show. Lets check the example of  get page name from page url.

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default5.aspx.cs" Inherits="Default5" %>

<!DOCTYPE html>

<html xmlns="">
<head runat="server">
    <title>Get the page name program in</title>
    <form id="form1" runat="server">
        <asp:Button ID="Button1" runat="server" Text="Get Page Name" OnClick="Button1_Click" />
        <br />
        <br />
        <asp:Label ID="lblresult" runat="server" Text=""></asp:Label>
Code Behind
using System;
using System.IO;

public partial class Default5 : System.Web.UI.Page
    protected void Page_Load(object sender, EventArgs e)

    protected void Button1_Click(object sender, EventArgs e)
        string pagename = Path.GetFileName(Request.Path);
        lblresult.Text = pagename;

Code generate the following output

Get the page name in c#

Jacob Lefore

Some say he’s half man half fish, others say he’s more of a seventy/thirty split. Either way he’s a fishy bastard. Google