Get the current page url by C#
How to get Current Page's Url in asp.net using C# code:
In this post we take a Example in this we want to get and
display the current page url. Get Paths and URL fragments from the HttpRequest
object? Path and url information related
to the application and the current request. Sometimes, we want to get the
current page URL that is displayed in the browser URL window on page. For
example if you want to let your visitors submit a blog post on your blogging website
you need to get that same exact URL.
Get Current Page URL Address in Asp.net:
Server.UrlEncode(Request.Url.ToString());
How to retrieve the URL of the current Page in ASP.NET:
Take a button control and a label control on page like this
<asp:Button ID="Button1" runat="server"
OnClick="Button1_Click"
Text="Submit"
/>
<br />
<br />
<asp:Label ID="Label1" runat="server"/>
Now on the button click event we want to display page current url in label.
ASP: How to Get the Current Page URL:
<%@ Page
Language="C#"
AutoEventWireup="true"
CodeFile="ckeck_url_by_code.aspx.cs"
Inherits="ckeck_url_by_code"
%>
<!DOCTYPE html PUBLIC "-//W3C//DTD
XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
<head id="Head1" runat="server">
<title>get current page url in asp.net</title>
<style type="text/css">
.style1
{
color: #990000;
font-size: x-large;
text-decoration: underline;
}
</style>
</head>
<body>
<form id="form1" runat="server">
<div align="center">
<div>
<span class="style1"><strong>Enter your name and click
on button:<br />
</strong></span>
<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
<asp:Button ID="Button1" runat="server"
OnClick="Button1_Click" Text="Submit" />
<br />
<br />
<asp:Label ID="Label1" runat="server"/>
</div>
</div>
</form>
</body>
</html>
Current Page in ASP.NET C# code:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
public partial class ckeck_url_by_code : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
Server.HtmlEncode(TextBox1.Text)
}
protected void Button1_Click(object sender, EventArgs e)
{
if (!String.IsNullOrEmpty(TextBox1.Text))
// Access the
HttpServerUtility methods through
// the intrinsic Server object.
Label1.Text = "Welcome in This Site,
<h1>"
+
+ "</h1>.<br/> <h1>your current page
url is</h1><br/> "
+
Server.UrlEncode(Request.Url.ToString());
// In this label we store given text message with current
pagr url
}
}
}
Example of getting Url:
Get the current page url |
Download Full code Example here..
Examples and other post related to Asp.net
- Check box in ASP.NET GridView
- Show grid view row details in to tooltip.
- How to Bind Gridview Form database.
- Limit Number of Characters in a TextArea using jQuery
- Limitation of Characters in Textbox or TextArea in asp.netusing jquery:
- Example of C# for Bind Data to asp.net Textbox inside gridview control
- Bind Dropdown by Dynamically
- Fill Dropdown By database.
- Cropping image using jQuery in asp.net
- jquery disable or Enable submit button after Validation
- Enable Disable Submit Button using jQuery
- Example of DropDownList inside GridView control
- Show gridview Row Details And Give Example.
- Introduction of Asp.net grid view Control.
- Bind Data to asp.net textbox control in inside of gridview Using C# Example
- Validation checkbox control using JavaScript
- Asp-checkboxlist control demo:
- Asp checkboxlist Example using C#
- Adding or binding tooltip in each item of dropdownlist
- Check box in asp Dropdown List.
- Example of Templatefield in asp.net gridview.
- DropDown List in asp.net Programming,
- Add ListItem in DropDownList asp.net c# Example
- Drop Down List control of asp.net
csharp language example codes to coders
ReplyDeletec# program code Load image source from a hard code directory