Weblog Of Nirandas | home

Developer From INDIA

Sending email using a gmail account in C#

clock November 17, 2009 00:35 by author Nirandas

Sending emails using your gmail account is very simple in C#/VB.NET using .NET framework 2.0+. The below code snippet shows how.
More...

Currently rated 5.0 by 1 people

  • Currently 5/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5


Generating tables for MySql providers

clock September 5, 2009 09:07 by author Nirandas

 While using MySQL connector/Net V6 and it's membership provider, the provider doesn't create tables it requires automaticly. After searching through internet, I got the solution. An extra attribute should be specified in order to create the schema automaticly.

More...

Be the first to rate this post

  • Currently 0/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5


Using Email instead of Username for logging in

clock April 25, 2009 03:26 by author Nirandas

ASP.NET provides various ready-made controls for making our life easier. One of them is Login control. ASP.NET Login control can be used for displaying a standard UI for user login.. The control displays two textboxs for entering username/password and a checkbox for indicating whether to remember the user on this computer. The Login control does not by default allow to set whether to use username and password as the log in or email and password should be used. In this post I'll show how we can easily change this behavior and allow our members to use their email address while logging in.

More...

Currently rated 4.0 by 1 people

  • Currently 4/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5


hide email and other sensitive information from spam harvesters

clock September 24, 2008 16:28 by author

Often we have to display email addresses and other contact information on our pages. For example providing a mailto link etc. However, along with the intended users, some other persons/bots are also interested in getting those email IDs for sending spams. For this, spammers use special bots for harvesting email/contact info from the web. In this post, I will show a method using javascript and any server side language by which we can easily protect such important information.

More...

Be the first to rate this post

  • Currently 0/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5


Displaying time in relative format

clock August 6, 2008 05:36 by author Nirandas

 

Many websites specially forum sites display time relative to the current time as "3 Hours 25 Minutes ago", "30 Seconds ago" etc. In this post I will show a method using which we can convert datetime into descriptive relative time string.

The method takes 2 parameters 1. the time to process, 2. the time to which the output will be relative. Usually it is DateTime.UtcNow. There is also an overload which only takes the time to process where the second parameter defaults to DateTime.UtcNow. Let us see some sample output of this function.

More...

Currently rated 5.0 by 1 people

  • Currently 5/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5


asp.net mvc: Is that username available?

clock July 29, 2008 16:44 by author Nirandas

I been using prototype for few of my project lately, however, I been hearing some wonderful things about jquery so decided that it is the right time to give it a shot. Here is what I tried to implement with jquery on asp.net mvc. I decided to add the ability to automatically check whether the username given by the user on the registration page is already taken or is available. For this I added a new action on the account controller named "check". This action returns a ContentResult containing the text to display. Code follows:

public ContentResult Check(string id) { if (Provider.GetUser(id, false) == null ) return Content(""); return Content("The username is already taken."); }

this function takes the username entered by the user as its parameter and checks if the username is available or not. If available, it returns nothing and if the name is already taken it returns the error message. After getting this done, now we will have a look at the changes made to the registration page's view.

The main change other than adding the jquery magic, is to add a span where to display the output from our check action. We will place it just after the text field for entering username. Modified table row of the username field is shown below.

<tr> <td>Username:</td> <td><%= Html.TextBox("username") %> <span id="isUsernameAvailableResult"></span> </td></tr>

after this, we will add the following script to the view. Note: I have included the jquery.js in this snippet, in real world you would probably have it included inside your master page.

<script src="/content/js/jquery-min.js" mce_src="/content/js/jquery-min.js" type="text/javascript"></script> <script language="javascript" type="text/javascript"> $(document).ready(function(){ $("#username").blur(function(){ $("#isUsernameAvailableResult").load( "check/" + escape(document.getElementById("username").value) + ".aspx"); }); }); </script>

Here we first add the anonymous function containing the actual code which does the ajax call to the blur event of the username text box. We do this inside the jquery special document.ready event)

The code just selects the span to contain the result and load the output of the ajax call into it. Here the request url is "/account/check/[user entered name here].aspx". Note: I use a modified routing rule in which the url always ends in ".aspx". This is to make it work it on iis 6 also without any big changes.

jquery is a great tool to have, and with the introduction of asp.net mvc, integrating jquery with asp.net is easyer than ever. Enjoy,

Digg It!DZone It!StumbleUponTechnoratiRedditDel.icio.usNewsVineFurlBlinkList

Be the first to rate this post

  • Currently 0/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5


Who Am I?

I am Nirandas - a developer from INDIA

Sign in