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.
Description:
In previous articles I explained create error log files in asp.net, bind all countries to dropdownlist in asp.net, generate random string or password in asp.net, Add or remove new row in gridview in asp.net, bind dropdownlist in gridview in asp.net, gridview examples in asp.net and many articles relating to dropdownlist, gridview, asp.net, c#,vb.net and jQuery. Now I will explain how to get current page name in asp.net using c#, vb.net with example.
In previous articles I explained create error log files in asp.net, bind all countries to dropdownlist in asp.net, generate random string or password in asp.net, Add or remove new row in gridview in asp.net, bind dropdownlist in gridview in asp.net, gridview examples in asp.net and many articles relating to dropdownlist, gridview, asp.net, c#,vb.net and jQuery. Now I will explain how to get current page name in asp.net using c#, vb.net with example.
// 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
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. |
|||
|
|||
1 comments :
How to Create demo images like above.....
Note: Only a member of this blog may post a comment.