Engineering

Export to excel in ASP.NET using C#

In this article we are going to show two examples of exporting to excel. First one is how to export grid view control to excel and the second one is how to export data table to excel.1-Export Grid View control to Excel:HtmlForm htmlForm = new HtmlForm(); string fileName = "attachment; filename=Reports.xls"; Response.ClearContent(); Response.AddHeader("content-disposition",...

Send email using C#

We are going to use Gmail outgoing mail server in our code here to demonstrate how you can send an email from your application using C#SmtpClient oSmtpClient = new SmtpClient(); oSmtpClient.Host = "smtp.gmail.com"; //The Outgoing mail server oSmtpClient.Credentials = new NetworkCredential("Your Email", "Your password"); oSmtpClient.Port = 587; oSmtpClient.DeliveryMethod = SmtpDeliveryMethod.Network; oSmtpClient.EnableSsl = true; MailMessage msg =...

Difference between 3 tiers and 3 layers applications

The terms tier and layer are frequently used interchangeably, but actually there is a difference between them:Tiers indicate a physical separation of components, which may mean different assemblies such as DLL, EXE, etc... on the same server or multiple servers; but layers refers to a logical separation of components, such...

Captcha image in C#.NET

What Captcha stand for?Completely Automated Public Turing test to tell Computers and Humans Apart. The Captcha technology help you to make sure your site is reasonably secure against automated attacks.Write the following code in a class named Captcha:public class Captcha { //make the captcha image for text public Bitmap MakeCaptchaImage(string txt,...

Make previous calendar dates not selectable in ASP.NET

In order to make all dates before the current date, not able to be selected, in the onDayRender event for your Calendar:if (e.Day.Date < DateTime.Today) { e.Day.IsSelectable = false; }To make it more obvious to the end user, also add:e.Cell.BackColor = Drawing.Color.GhostWhite; e.Cell.ForeColor = Drawing.Color.Gainsboro;

Get the referring page on Page_Load event in ASP.NET

When a page loads, in order to get the name of the page that sent you there, all you need to use is:Request.UrlReferrer.ToString();You can create a global variable to hold it:string sReferrer = "";Then, in the Page_Load event, assign it:if (!Page.IsPostback) { sReferrer = Request.UrlReferrer.ToString(); }Or, you can put...