ASP.NET Tutorials for beginners

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;
// https://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 install ASP.NET
What is ASP.NET?
ASP.NET Versions
ASP.NET Custom controls
ASP.NET …

Learn more

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;
– Use IIS …

Learn more

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: https://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”;

Learn more

How to learn ASP.NET

You can learn the basics of .NET first, then to watch some videos, you can also try some quick examples.

To learn more about data-access in .NET you could visit SQL tutorials. This is an important part of learning .NET.

You could also read some of the best programming books at ASP.NET books section.

Related TutorialsASP.NET Pages
How to refresh an …

Learn more

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. This Web Forms ASP.NET tutorial will show you how to achieve this.

Adding Custom Control to the Toolbox

1. Create a test Web Forms page. (WebForm1)
2. Using Tools menu, click Add/Remove Toolbox Items.
3. …

Learn more

How to connect to MySQL database using ASP.NET hosting

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

Connect to MysQL database using C# using 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 …

Learn more

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 some task, …

Learn more

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 contents of …

Learn more

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” “https://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd”>

<html xmlns=”https://www.w3.org/1999/xhtml”>

<head runat=”server”>

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

</head>

<body>

<form id=”form1″ runat=”server”>

Learn more

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 {

background-color: …

Learn more