Tuesday, January 31, 2012

How to check if column existed by a simple way in MS SQL?

                  IF COL_LENGTH('TableName','ColumnName') IS NULL

                  BEGIN

                        exec sp_executesql @SQLStatement

                  END

CAPTCHA for Asp.Net MVC

http://www.stefanprodan.eu/2012/01/user-friendly-captcha-for-asp-net-mvc/

AttributeRouting, a ASP.NET MVC open source project

https://github.com/mccalltd/AttributeRouting/wiki/2.-Usage

Multiple Routes Mapped to a Single Action

You can specify multiple GET routes that map to a single action simply by adding more than one route attribute. This can be handy when supporting legacy urls. To specify the order of these routes, use the Order parameter. This is important because the first route will be used to generate outbound URLs.
  [GET("", Order = 1)]
  [GET("Posts", Order = 2)]
  [GET("Posts/Index", Order = 3)]
  public void Index()
  {
      return View();
  }

Tuesday, January 24, 2012

What is User Agent Style Sheet?

The default formatting, it is the cornerstone of CSS cascading.

1.    user agent declarations

2.    user normal declarations

3.    author normal declarations

4.    author important declarations

5.    user important declarations

Reference:

Monday, January 23, 2012

How to align Header and Column in MvcContrib

.Columns(column =>
{
           

column.For(clmn => clmn.Id).Named("ID").HeaderAttributes(style => "text-align:center;");
column.For(a => Html.ActionLink("Edit", "Edit", new { id = a.RequestId })).Named("Edit").HeaderAttributes(style => "text-align:center;").Attributes(style => "text-align:center;");

})

An approach to mobile support in ASP.NET MVC

http://jclaes.blogspot.com/2012/01/approach-to-mobile-support-in-aspnet.html

Tuesday, January 17, 2012

Rounded corner by css

.rounded-corners {
     -moz-border-radius: 20px;
    -webkit-border-radius: 20px;
    -khtml-border-radius: 20px;
    border-radius: 20px;
}


http://jonraasch.com/blog/css-rounded-corners-in-all-browsers

What is NoSQL

NoSQL databases aim to save Business Entities directly to a persistence store without O-R Mapping.

NoSQL stands for ‘Not only SQL’. Martin Fowler recently posted on his blog that calling NoSQL as ‘Not only SQL’ is unnecessarily polite. It should mean ‘NO-SQL’. 


Reference:
http://www.devcurry.com/2012/01/hello-ravendb-introducing-ravendb-for.html

Dream it, plan it, build it, launch it, a nice website

http://www.atlassian.com/how-it-works

Monday, January 16, 2012

How to recursively disable all of elements inside a div by Javascript?

<script type="text/javascript">

    $('#readonlydiv').ready(function () {

        RecursiveDisable(document.getElementById("readonlydiv"));

    });



    function RecursiveDisable(element) {

        try {

            element.disabled = element.disabled ? false : true;

        }

        catch (E) {

        }

        if (element.childNodes && element.childNodes.length > 0) {

            for (var x = 0; x < element.childNodes.length; x++) {

                RecursiveDisable(element.childNodes[x]);

            }

        }

    }

How to handle multiple buttons in one form in ASP.NET MVC?


1.      Razor view:

@using (Html.BeginForm())

{

    <fieldset>

        <legend>Edit </legend>

        <div class="editor-label">

            @Html.LabelFor(model => model.ID)

        </div>

        <p>

            <input name ="button" type="submit" value="Save" />

            <input name ="button" type="submit" value="Reject" />

            <input name ="button" type="submit" value="Accept" />

            <input name ="button" type="submit" value="Complete" />

        </p>

    </fieldset>

}



2.  Controller

        [HttpPost]

        public ActionResult Edit(string button)

        {

            switch (button)

            {

                case "Save":

                    break;

            }

            return RedirectToAction("Index");

        }


Thursday, January 12, 2012

How to validate Model Data using Data Annotations Attributes but you don’t want to change Model layer?

How to validate Model Data using Data Annotations Attributes but you don’t want to change Model layer?


In MVC, you could use Data Annotations Attributes to validate Model Data. Reference:




But what if model layer is from another layer, you don’t want to change anything on that class?

Solution: MetadataTypeAttribute


Steps:

1.      Create a class inherent the class from Another layer

2.      Add MetadataTypeAttribute to point to another class 
3.   Add Data Annotation into second class

Code example:

    public class ValidationExtension
    {
             [Required(ErrorMessage = "Title is required.")]
       public string Title;
    }


    [MetadataType(typeof(ValidationExtension))]
    public class MVCModelLayerClass: BusinessLayerClass
      {

    }








How to send a mail with an ics appointment as attachment with System.Net.Mail

http://blog.krisvandermast.com/HowToSendAMailWithAnIcsAppointmentAsAttachmentWithSystemNetMail.aspx

Friday, January 6, 2012

How to make one field is optional (not required) in ASP.NET MVC data annotations for validation?


Make that field is nullable in model. Such as:

        [Display(Name = "ID")]

        public int? ID { get; set; }


Wednesday, January 4, 2012

Need to clear up session data when log out in ASP.NET

Session.Abandon

http://msdn.microsoft.com/en-us/library/ms524310.aspx



If you do not call the Abandon method explicitly, the server destroys these objects when the session times out.

How to delete a user from ASP.NET membership database by SQL?

   DECLARE @UserId uniqueidentifier

   SET @UserId = 'userid in here F6817A3F-D0AF-4715-8A5C-4750E2C9EA2D'
   
   DELETE FROM aspnet_Profile WHERE UserID = @UserId

   DELETE FROM aspnet_UsersInRoles WHERE UserID = @UserId

   DELETE FROM aspnet_PersonalizationPerUser WHERE UserID = @UserId

   DELETE FROM dbo.aspnet_Membership WHERE UserID = @UserId

   DELETE FROM aspnet_users WHERE UserID = @UserId


Eight Ways to Transfer Data from One Page to Another Page in ASP.NET webform

http://www.eggheadcafe.com/tutorials/asp-net/e653f028-01fb-4d0e-843b-058deae562a2/eight-different-ways-to-transfer-data-from-one-page-to-another-page.aspx
1. Use the querystring:

2. Use HTTP POST:

3. Use Session State:

4.  Use public properties:

5. Use PreviousPage Control Info:

6. Use HttpContext Items Collection:

7. Use Cookies:

8. Use Cache:


Tuesday, January 3, 2012

What is partial view in ASP.NET MVC 3?

Create reusable content with Razor syntax, like user control in ASP.NET web form.



How to open a new window or tab in ActionLink

@Html.ActionLink(”New window”, "test", "Home", new { target = "_blank" })

Or use html A link directly.