programming we consider all important topic for knowledge about controls,web Services, JSON, Ajax, database, and interview related Question. In this and sql server tutorial blog we give many examples of jquery as like How Play YouTube Video in Your Website by URL, How to Play YouTube Videos in by using Jquery , Jquery Change div background on mouseover in , JQuery UI Datepicker (Calendar) etc.

Monday, September 15, 2014

Get the current page url by C#

How to get Current Page's Url in 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


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" ""> 

<html xmlns="" >
<head id="Head1" runat="server">

    <title>get current page url in</title>
    <style type="text/css">
    <form id="form1" runat="server">
    <div align="center">
        <span class="style1"><strong>Enter your name and click
        on button:<br />
        <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"/>


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)
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 by C#
 Get the current page url 

1 comment: