Get the page name example in c#

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#

Get the page name example in c# Get the page name example in c# Reviewed by Jacob Lefore on August 17, 2015 Rating: 5

No comments