Skip to main content

Posts

Showing posts from November, 2011

How to send Email through ASP.NET in C#

Sending Email through ASP.NET is very easy.the .NET framework comes with a namespace which is uses for handling the Email.The namespace is:                                                            System.Net.Mail namespace Here i am using the two classes of the above mentioned namespace.The first class is MailMessage  class which is used for actual email and second is SmtpClient class which is for sending Email. Write the following code into the page load event: try { MailMessage mailMessage = new MailMessage(); mailMessage.To.Add( " test@domain.com " ); mailMessage.From = new MailAddress( " test2 @ domain.com " ); mailMessage.Subject = " Test Email " ; mailMessage.Body = " This is an ASP.NET test E-mail! " ; SmtpClient smtpClient = new SmtpClient( " smtp .testISP.com" ); smtpClient.Send(mailMessage); Response.Write( " E-mail sent! " )

How to upload a file on the server through upload control in asp.net

With ASP.NET upload a file on the server is very easy.With FileUpload control we can easily upload a file on the server.Following markup is required.   < form id ="form1" runat ="server" > < asp:FileUpload id ="FileUploadControl" runat ="server" /> < asp:Button runat ="server" id ="btnupload" text ="Upload" onclick =" btnupload _Click" /> < asp:Label runat ="server" id ="lblstatus" /> </ form > Here is the CodeBehind code required to handle upload a file on the server. protected void btnupload _Click( object sender, EventArgs e) { if (FileUploadControl.HasFile) { try { string filename = Path.GetFileName(FileUploadControl.FileName); FileUploadControl.SaveAs(Server.MapPath( " ~/ " ) + filename); lblstatus .Text = " Upload status: Fi

How to use ASP.NET AJAX UpdateProgress Control

Some time we have a method which takes a bit more time to execution.Due to this time consumption user get impatient One of  Ajax control solved this problem which is ASP.NET AJAX Update Progress Control. ASP.NET AJAX Update Progress Control provides status information about page updates. Here I am going to explain how to use ASP.NET AJAX Updated Progress Control in a web page. Firstly we need a animated GIF.I am using the following image.  In case of Visual studio 2005 install AjaxControlToolkit and in case of Visual studio 2010 add AjaxControlToolkit.dll in the project. Firstly we have to add scriptmanger inside the form tag.   <asp:ScriptManager ID="ScriptManager1" runat="server" />  And Use updatePanel because we need partial update of page. And drag updateProgress from toolbox to the page.                                      After that page will be look like this:         Code:                                                             

ASP.NET AJAX PasswordStrength Extender

  AJAX Password Strength Extender shows the strength of user chosen passwords.the strength can be show in a  text form, a bar indicator or combination of both.Now i am going to show you how to add ajax password extender control to a asp.net page, In case of Visual studio 2005 install AjaxControlToolkit and in case of Visual studio 2010 add AjaxControlToolkit.dll in the project. I have added a text box and a label control in the page and page will be look like this:                                               After that Add password strength code in the aspx file of the web page. <body>     <form id="form1" runat="server">         <asp:ScriptManager ID="ScriptManager1" runat="server" />       <div>                        &nbsp; Status Bar Indicators<br />         &nbsp;         <asp:TextBox ID="TextBox2" runat="server"></asp:TextBox><br />         &nbsp;

C# Console Application

A Console Application Screen is look like this:     To Create Console Application open Visual studio and click File from the menu bar at the top.From the file menu select New Project. When you click on New Project Following window will be appear.                                                                                                  In Case of Visual Studio 2010 window will be look like this: When you click OK , a new Console Application Project will be created.Some Code should be displayed.    Above is the Program.cs File in the Solution Explorer.Here You can write code according to your requirement.Then save the Program and run the Application.Your output will be show on the console window. Happy Programming..:)

How to write events in C#

We're going to display a simple message box when the button is clicked.So we need a coding window. To see the code for the button double click the button you added to the form. the coding window will open, and your cursor will be inside of the button code. It will look like this:   We want to display a message box, with some text on it. This is quite easy to do in C#. Position your cursor between the two curly brackets. Then type a capital letter "M". You'll see the IntelliSense list appear:            After type 'ess' You'll see the IntelliSense list appear:                                                                          When you have MessageBox selected, hit the enter key on your keyboard (or double click the entry on the list). The code will be added for you: After that type '.show' and then type message which you want to display in the message box. The code

How to add Controls to a Blank C# Form

If you want to add a control to a form, you can use the Toolbox on the left of Visual Studio. Move your mouse over to the Toolbox, and click the plus symbol next to Common Controls. You should see the following list of things that you can add to your form: Toolbox Click the Button item under the Common Controls heading. This will select it. Now click once anywhere on your form. A button will be drawn for you, and your Form will look like this: Form                                           Similarly you can drag and drop different controls on the Form According to your requirements. The text on the button, which defaults to "button1", can be changed from properties windows.  A property of a control is things like its Height, its Width, its Name, its Text, and a whole lot more besides. To see what properties are available for a button, make sure the button is sele

How To Create Windows Form Application in C# Part 1

To create a C# Windows application Open visual studio On the  File  menu, click  New Project . The  New Project  dialog box appears. This dialog box lists the different default application types that Visual C# Express Edition can create. Select  Windows Forms Application  as your project type. Change the name of your application. Click  OK . Or in VS 2010: When you click OK, a new Windows Application project will be created To see the window where you'll write most of your code, right click  Form1.cs  in the Solution Explorer: Now double click  Form1.Designer.cs . You'll see the following code: Here you can write your code according to requirement. After that You can  Debug the Application     From the   menu at the top, click   Start Debugging   (Or you can just press the F5 key on your keyboard.): In next post i will tell you how to drag controls on Form and how to write control events. Happy Programming :)