Subscribe For Free Updates!

We'll not spam mate! We promise.

Wednesday, 29 May 2013

How to Send Mail form Asp .Net Website


 Here i am describing how to Send mail from website


This is a common function Required for every website.
 For this you have to add  System.Web.Mail namespace 

The System.Web.Mail namespace contains classes that enable you to construct and send messages using the CDOSYS (Collaboration Data Objects for Windows 2000) message component. The mail message is delivered either through the SMTP mail service built into Microsoft Windows 2000 or through an arbitrary SMTP server. The classes in this namespace can be used from ASP.NET or from any managed application.
For more info about  System.Web.Mail click here.

-Create a website and design the Form like below screen

or copy this code in source code and paste within < form > tag

now go to code view and write below code

For validation just write the below javascript code in your head tag

Now you can send mail 
This example is for sending mail from Gmail.
If you want any server mail just change the smtp server details with port number and use it.

Maintain Scroll Position On Postback

Recently i faced problem to maintain scroll position in my page which having A grid with some radio button and check box with autopostback within a Updatepanel.
The main problem is when a postback occur the page is moving to top. i tried a lot and finally got the solution .
1.if you are using IE then its very simple just put the code in your page directive.
but it will not work in Firefox for that you have to add one browser file into your website
Right click on solution explorer > Add New Item
Select Browser File and add it to App_Browsers folder.
Add MaintainScrollPositionOnPostback capability to this browser file as written below.
Some times this also not work,
Then a simple solution just add a blank Update panel after the grid and onpostback just put the focus to that update panel
it will work in any browser.
in cs postbackevent
if any problem just feel free to ask or any modification reply.