Monday, April 22, 2013

How to convert ASP.NET textbox input value into upcase right way?

Add following javascript into ASP.NET textbox control

Friday, April 19, 2013

How to add ajax validation on field in ASP.NET MVC 3?
By Remote Attribute. This way is MS designed for you.

//In Model
        [Remote("CheckExistedEmail", "ControllerName")]
        [Required]
        [DataType(DataType.EmailAddress)]
        [Display(Name = "Email address")]
        [RegularExpression(@"^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,4})$",ErrorMessage="Invalid email address")]
        public string Email { get; set; }

//In Action 
        public JsonResult CheckExistedEmail(string Email)
        {
            if (EmailExisted(Email))
            {
                return Json("Existed Email.", JsonRequestBehavior.AllowGet);
            }
            else
            {
                return Json(true, JsonRequestBehavior.AllowGet);
            }
        }

http://msdn.microsoft.com/en-us/library/gg453903(v=vs.98).aspx

Thursday, April 18, 2013

How many ways to redirect URL in Javascript?

1. window.location.href=”login.htm";
2. window.navigate(”login.htm”);
3. self.location=”login.htm”;

Any other way?

Wednesday, April 17, 2013

How to disable browser back button in asp.net?

Should make ASP.NET page cache expired instead of disable browser back button

Page.Response.Cache.SetCacheability(HttpCacheability.NoCache)

Tuesday, April 16, 2013

How to get active users in last 10 minutes in ASP.NET membership database?

select top 300 * from dbo.aspnet_Users u
where u.LastActivityDate > DATEADD(minute, -10, GETUTCDATE())
order by u.LastActivityDate desc