Asp.net : Get the current page (webform) name

In this article I am going to explain how to get the current wedform (page) name in asp.net code behind using C# and vb.net

Implementation:

Import the namespace

C# code:
using System.IO;

VB.net Code:
Imports System.IO

Get Current page name
Create a method to get the page name.

C# code:
protected void Page_Load(object sender, EventArgs e)
    {
        GetCurrentPage();
    }

    public void GetCurrentPage()
    {
        string currentPagename =Path.GetFileName(Request.Url.AbsolutePath);
        lblpagename.Text = "Current page name is : "+currentPagename;
    }

VB.net code:
Protected Sub Page_Load(sender As Object, e As EventArgs) Handles Me.Load
        GetCurrentPage()
    End Sub
    Protected Sub GetCurrentPage()
        Dim currentPagename As String = Path.GetFileName(Request.Url.AbsolutePath)
        lblpagename.Text = "Current page name is : " + currentPagename
    End Sub

Post a Comment

0 Comments