How to get current page URL in ASP.NET

To get the current page URL you could use HttpContext.Current.Request.Url:

1. To get the full URL with query string (if any) you could use:

string absoluteurl = HttpContext.Current.Request.Url.AbsoluteUri;
// http://localhost:80/test/Default.aspx?test=1

2. To get the path without the domain you could use:

string absolutepath = HttpContext.Current.Request.Url.AbsolutePath;
// /test/Default.aspx

3. To get the Host:

string host = HttpContext.Current.Request.Url.Host;
// localhost

Related TutorialsHow to refresh an image in ASP.NET
ASP.NET […]

How to speed up ASP.NET web site

Many times, when you create larger ASP.NET site you need to optimize the application and IIS web server, so to improve the user experience. We say that the ASP.NET website is good optimized when server response time is bellow 200 ms (milliseconds).

Speed up ASP.NET web site

You can improve your ASP.NET website performance when:

– Use ASP.NET Caching;
– […]

How to zip a file or a folder in ASP.NET

You can zip a file or a folder in ASP.NET by using java.util.zip.ZipFile, ICSharpCode.SharpZipLib.Zip or other library assemblies.

SharpZipLib can be downloaded from: http://www.icsharpcode.net/OpenSource/SharpZipLib/Download.aspx.

The ASP.NET examples below demonstrate how to zip files.

using ICSharpCode.SharpZipLib.Zip;
using System.IO;

ZipOutputStream zos = null;
protected void Button1_Click(object sender, EventArgs e)
{
string[] pathCollection = new string[2];
PathCellction[0] = “c:\\folder1”;
[…]

How to learn ASP.NET

You can learn ASP.NET at http://www.howtoasp.net/tutorials/asp-net-tutorials/. You can learn the basics of ASP.NET first, then to watch some videos, you can also try some quick examples.

To learn more about data-access in ASP.NET you could visit http://www.howtoasp.net/tutorials/database-tutorials/. This is an important part of learning ASP.NET.

You could also read some of the best ASP.NET books at http://www.howtoasp.net/asp-net-books/.

Related […]

How to Create a Custom Control in ASP.NET

If none of the existing ASP.NET server controls meet your requirements, then you can create a custom control by deriving from one of the base control classes.

Adding Custom Control to the Toolbox

1. Create a test Web Forms page. (WebForm1)
2. Using Tools menu, click Add/Remove Toolbox Items.
3. On the .NET Framework Components tab of the Customize ToolBox […]

How to connect to MySQL database using ASP.NET hosting

Many developers use ASP.NET with MySQL with their applicaions. If you use ASP.NET hosting services and some of ASP.NET languages as VB.NET or C# then you could connect to the MySQL databse using ODBC .net data provider.

Connect to MysQL database using C# on ASP.NET hosting

OdbcConnection cn = new OdbcConnection(“Driver={MySQL ODBC ODBC 5.2a Driver};Server=localhost or remote;Database=test;User=user;Password=pass;Option=3;”);

OdbcCommand cmd […]

How to disable a button after click in ASP.NET

This is a very common scenario when you would like to disable button after click, so the user could not click it again if you need some time to do some task which takes longer time to be executed.

Disable a button after click in ASP.NET before the PostBack

If you would like to disable button to do […]

How to write encoded text on the web page in ASP.NET

When you want to write encoded text on the web page you should use the Literal control, because it does support a property that is not supported by the Label control: the Mode property. The property enables you to encode HTML content and accept any of the following three values:

–  PassThrough—Displays the […]

How to associate a Label with a TextBox or other Form control in ASP.NET

The next code shows how you can attach an asp:Label control with the asp:TextBox. In this case when the user clicks the Label the application will focus on the TextBox.

 

TestAssociate.aspx

<%@ Page Language=”vb” AutoEventWireup=”false” CodeBehind=”TestAssociate.aspx.vb” Inherits=”TextChange.TestAssociate” %>

<!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 runat=”server”>

<title>Associate a Label with a TextBox</title>

</head>

<body>

<form […]

How to use different colored highlights in a select menu with CSS

You can assign classes to menu options, to create multiple background colors within the drop-down color. In this case you need to set only the color and background-color properties for a menu item. The next two test files show this:

 

File test.css

.blue {

background-color: #ADD8E6;

color: #000000;

}

.red {

background-color: #E20A0A;

color: #ffffff;

}

.green {

Recommended ASP.NET Examples