Aspdotnet-Suresh

aspdotnet-suresh offers C#.net articles and tutorials,csharp dot net,asp.net articles and tutorials,VB.NET Articles,Gridview articles,code examples of asp.net 2.0 /3.5,AJAX,SQL Server Articles,examples of .net technologies

Get Current Page Name in Asp.net using C#, VB.Net with Page.GetFileName Property

Aug 5, 2015
Introduction

Here I will explain how to get current page name in
asp.net using c#, vb.net with example or get name of current executing page in asp.net using c#, vb.net or get currentpage.aspx from page object in asp.net. By Path.GetFileName property we can get current page name in asp.net using c#, vb.net.


To get current page name in asp.net we need to write the code like as shown below


// Get Current Page Name
string pageName = Path.GetFileName(Request.Path);

If you want to check complete example open your aspx page and write the following code


<html xmlns="http://www.w3.org/1999/xhtml">
<head id="Head1" runat="server">
<title>Get Current Page Name in Asp.net using c#, vb.net</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:Button ID="btnGet" runat="server" Text="Get Current Page Name" onclick="btnGet_Click" /><br /><br />
<asp:Label ID="lblresult" runat="server" ForeColor="Green" />
</div>
</form>
</body>
</html>

Now add following namespaces in code behind

C# Code


using System;
using System.Web;
using System.IO;

After completion of adding namespaces you need to write the code like as shown below


protected void Page_Load(object sender, EventArgs e)
{

}
protected void btnGet_Click(object sender, EventArgs e)
{
// Get Current Page Name
string pageName = Path.GetFileName(Request.Path);
lblresult.Text = "Current Page Name is: " + pageName;
}

VB.NET Code


Imports System.Web
Imports System.IO

Partial Class VBCode
Inherits System.Web.UI.Page
Protected Sub Page_Load(sender As Object, e As EventArgs)
End Sub
Protected Sub btnGet_Click(ByVal sender As Object, ByVal e As EventArgs)
' Get Current Page Name
Dim pageName As String = Path.GetFileName(Request.Path)
lblresult.Text = Convert.ToString("Current Page Name is: ") & pageName
End Sub
End Class

Demo

Get Current Page Name in Asp.net using C#, VB.Net with Page.GetFileName Property

If you enjoyed this post, please support the blog below. It's FREE!

Get the latest Asp.net, C#.net, VB.NET, jQuery, Plugins & Code Snippets for FREE by subscribing to our Facebook, Twitter, RSS feed, or by email.

subscribe by rss Subscribe by RSS subscribe by email Subscribe by Email

1 comments :

Shrikesh kale said...

How to Create demo images like above.....

Give your Valuable Comments

Note: Only a member of this blog may post a comment.

© 2015 Aspdotnet-Suresh.com. All Rights Reserved.
The content is copyrighted to Suresh Dasari and may not be reproduced on other websites without permission from the owner.