Wednesday, December 26, 2012

asp.net Response.RedirectToRoute issue

In my global.ascx I have the routing setup: 
routeCollection.MapPageRoute("My Home Page", "myhomepage/{myid}", "~/MyHomePage.aspx");
I use Response.RedirectToRoute() with a parameter to open a page. I identified that in the following cases the redirect will fail:
  • The parameter is not given. e.g. Response.RedirectToRoute("My Home Page");
  • The parameter as null value. e.g. Response.RedirectToRoute("My Home Page", new {myid = null});
  • The parameter as null value. e.g. Response.RedirectToRoute("My Home Page", new {myid = string.empty});

Apparently you MUST give a non-empty value to the parameter.

regular expression for character range

regular expression for character range:
e.g. between 1 and 500:
^.{1,500}$

Thursday, December 20, 2012

fix asp.net checkboxlist wierd layout

on one page my checkboxlist shows up correctly, on another it never does. After hours of trying I figured this out: assign CheckBoxList class to your css class of the checkboxlist, play with the properties inside the class will help you fix the issues.


         .CheckBoxList input
        {
            margin-left: -10px;
        }
        .CheckBoxList td
        {
            padding-left: 10px;
            width:80%;
        }

t-sql change a column from nullable to not null and add default value it


--1.make sure all records have a value in the column
update [TableName]
SET [ColumnName] = [Default Value]

--2. change the column to not null
ALTER TABLE [TableName]
ALTER COLUMN [ColumnName] [data type] NOT NULL
GO

--3. add default value constraint to the column
ALTER TABLE [TableName] WITH NOCHECKADD CONSTRAINT [DF_DefaultName] DEFAULT [Default Value] FOR [ColumnName]
GO

Wednesday, December 05, 2012

jquery to check if an asp.net checkbox control is selected or unselected:

$('input[id$=cb1]').is(':checked'){
          //your code here
}