Archive of: ASP

  1. Grouping Radio Buttons in ASP .NET MVC 2 posted August 27, 2010

    Here’s a simple issue I ran into today when dealing with radio buttons in an ASP .NET MVC 2 application.

    Radio buttons should only allow the user to select a single option out of multiple choices. This should be enforced by only allowing one radio button to be selected for each option set. But, what if your application has multiple options that all need radio buttons? How do you distinguish the radio buttons from one option from the other.

    This is where groups comes in. By setting the GroupName property for each of your radio buttons, you can specify which buttons to associate to an option.

    <div>
      <asp:RadioButton ID="ActionMatch" GroupName="RegexActions" Checked="true" Text="Match" runat="server" />
      <asp:RadioButton ID="ActionReplace" GroupName="RegexActions" Text="Replace" runat="server" />
    </div>
    

    Also, note that in ASP .NET MVC 2 there is no default group, so you must define a GroupName in order for the radio buttons to work properly.

  2. Sending Email in ASP .NET posted February 17, 2010

    I can’t think of too many websites that don’t send automated email. Unfortunately, for ASP .NET programmers, there are several incorrect and out-of-date code snippets online which try to explain how to send email.

    Here’s the code I use on the contact form for my personal website which does the trick quite nicely.

    /* using System.Net.Mail; */
    MailMessage newMail = new MailMessage();
    newMail.To.Add(toAddress);
    newMail.Subject = subject;
    newMail.Body = body;
    newMail.From = new MailAddress(fromAddress, name);
    newMail.IsBodyHtml = true;
    
    SmtpClient SmtpSender = new SmtpClient();
    SmtpSender.Port = 25; //or, whatever port your SMTP server operates on
    SmtpSender.Host = "mail.yourdomain.com";
    SmtpSender.Send(newMail);
    

    Here, I’m using MailMessage to build the actual email message to be sent and SmtpClient to do the actual sending.

    Now, the Web.config file needs to be updated so the server knows your email account credentials.

    Add this code to your Web.config file before the final </configuration> tag:

    <system.net>
      <mailSettings>
        <smtp>
          <network defaultCredentials="false"
               host="mail.yourdomain.com" port="25"
               userName="name-to-send-email@yourdomain.com"
               password="*****"/>
         </smtp>
       </mailSettings>
    </system.net>
    

    Now, you should be able to send automated email messages to your heart’s content. Enjoy.

    Image From blueskyfactory
.NET Algorithmic Art ASP ASP .NET ASP .NET MVC audio Bill Gates C# code review Computational Art CouchDB CSS Database DateTime debug DevDays eclipse ethics FileSystem Git Improvement iPhone Java JQuery Knopflerfish Layouts mail Microsoft Oracle OSGi Processing Python Ruby SMTP SOA Software Piracy Source Control SQL StackOverflow tools TortoiseGit training Web Standards Windows XHTML