Thursday, December 2, 2010

Masterpage's button event not firing

Add this to buttons attributes
CausesValidation="false" UseSubmitBehavior="false"
Also check if there are any validators on the content page with no ValidationGroup

A potentially dangerous Request.Form value was detected from the client

You may see this error when you are insert html in asp.net forms. To fix this just append this at the top of page

ValidateRequest="false"
But if you are using dot net framework 4, you also need to add this in the web.config file

<httpRuntime requestValidationMode="2.0"></httpRuntime>
and you are done.

For selected folders use "location" object inside folder and place above code inside that

<location path="{path}">
    <system.web>
        <httpRuntime requestValidationMode="2.0" />
    </system.web> 
</location>

Sunday, November 28, 2010

Simple link rollover using css

Creating  a simple image rollover using css is easy and great to use. It can be used in menus and banners and else where with a few modification.
For example if you you want to create a css menu button

<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title>Simple link rollover using css</title>
    <style type="text/css">
        a
        {
            background#0099CC;
            color#FFFFFF;
            displayblock;
            padding4px;
            text-aligncenter;
            text-decorationnone;
            width99px;
        }
        a:hover
        {
            backgroundAliceBlue;
            color#000;
        }
    </style>
</head>
<body>
    <a href="#">Click Me</a>
</body>
</html>
 
you can even use a image instead of just color. To do so just append the following to background.

a 
{
    backgroundurl(image-normal.png);
}
and

a:hover 
{
   backgroundurl(image-hover.png);
}

Tableless form using HTML with CSS

Making a tableless form design using HTML with CSS is very easy. It is a good practice because tables are slower than div tags.

<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title>Tableless form design using HTML with CSS</title>
    <style type="text/css">
        form div label
        {
            width112px;
            displayinline-block;
        }
        form div
        {
            margin0.5em 0;
        }
    </style>
</head>
<body>
    <form>
        <div>
            <label for="txtName">Name</label>
            <input name="txtName" id="txtName" />
        </div>
        <div>
            <label for="txtEmail">Email</label>
            <input name="txtEmail" id="txtEmail" />
        </div>
        <div>
            <label for="txtMobile">Mobile</label>
            <input name="txtMobile" id="txtMobile" />
        </div>
        <div>
            <label for="txtComments">Comments</label>
            <input name="txtComments" id="txtComments" />
        </div>
        <div>
            <input type="submit" value="Submit" />
        </div>
    </form>
</body>
</html>

Saturday, November 27, 2010

Adding www to your domain with htaccess

The script below adds www to all the requests without the prefix www e.g. example.com and converts it to www.example.com

RewriteEngine On
RewriteCond %{HTTP_HOST} !^www\.
RewriteRule ^(.*)$ http://www.%{HTTP_HOST}/$1 [R=301,L]

Line one -> Switch on Rewrite Engine
Line two -> Looks for url without www and captures the rest of url
Line three -> Add the www to previous captured url and forwards the request