Code & !Code: Code: ASP.Net MVC Maintain Checkbox State

December 27, 2009 · Leave a Comment
Filed under: ASP, ASP.NET, ASP.NET 2.0, Featured 

Below is a quick and dirty way to maintain a check box checked state during postbacks with MVC:

<%= Html.CheckBox("IsSecure", (Request.Form["IsSecure"] ?? string.Empty).Contains("true"))%>

Assign Value to Asp.Net TextBox with mode="Password" | Official

September 12, 2009 · Leave a Comment
Filed under: ASP, ASP.NET, ASP.NET 2.0, Featured 

ASP.NET server control doesn’t add/display the value in a password textbox because of security concerns. On most of the web sites at the time of registration password is asked. You must have noticed after submitting the page if you are again redirected to the page due to unsuccessful registration value of password field is lost.This is due to security concerns as everything is gets rendered on the client side So when you view the source in the browser password value will be there.

Solution 1

Add an attribute to textbox.Add this following line of code when you want set the value

TextBox1.Attributes.Add("value", "thePassword")

Above solution will work, but if a user does view source on the form, the password is visible as plain text and that is never good from a security point of view. Rather, I would use Viewstate to hold the password value and if the user doesn’t change it then retrieve the value from view state.

Solution 2

But if explicitly you want to set the value of password text box again then use following method in .NET 2.0

txtPassword.Attributes["value"] = Request.Form[txtPassword.ClientID]; //in C#.Net 2.0

Enjoy.. example: How to set change DetailsView pager font name

September 4, 2009 · Leave a Comment
Filed under: ASP, ASP.NET, ASP.NET 2.0, Featured 

How to set change DetailsView pager font name programmatically in


<%@ Page Language="C#" AutoEventWireup="true" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "">

<script runat="server">
    protected void Button1_Click(object sender, System.EventArgs e)
        DetailsView1.PagerStyle.Font.Name = "Comic Sans MS";

<html xmlns="" >
<head id="Head1" runat="server">
    <title>How to set change DetailsView pager font name programmatically in</title>
    <form id="form1" runat="server">
        <h2 style="color:Navy; font-style:italic;">DetailsView Example: Change Pager Font Name</h2>
            ConnectionString="<%$ ConnectionStrings:NorthwindConnectionString %>"
            SelectCommand="Select Top 10 ProductID, ProductName, QuantityPerUnit, UnitPrice, UnitsInStock From Products"
            HeaderText="Product Details"
            <RowStyle Height="30" />
                <asp:BoundField DataField="ProductID" HeaderText="Product ID" ReadOnly="true" />
                <asp:BoundField DataField="Productname" HeaderText="Product Name" />
                <asp:BoundField DataField="QuantityPerUnit" HeaderText="Quantity Per Unit" />
                <asp:BoundField DataField="UnitPrice" HeaderText="Unit Price" />
                <asp:BoundField DataField="UnitsInStock" HeaderText="Units In Stock" />
        <br />
            Text="Change DetailsView Pager Font Name"

Create a Virtual Directory in IIS 7.0

March 12, 2009 · 1 Comment
Filed under: .Net, C#, Featured, IIS, VB.Net 


A virtual directory is a directory name, used in an address, which corresponds to a physical directory on the server. You can add a virtual directory that will include directory content in a site or an application without having to move the content physically into that site or application directory.

To add a virtual directory

You can perform this procedure by using the user interface (UI), by running Appcmd.exe commands in a command-line window, by editing configuration files directly, or by writing WMI scripts.
User Interface
To use the UI


Open IIS Manager. For information about opening IIS Manager, see IIS 7.0: Open IIS Manager.

In the Connections pane, expand the Sites node in the tree, and then click to select the site in which you want to create a virtual directory.

In the Actions pane, click View Virtual Directories.

On the Virtual Directories page, in the Actions pane, click Add Virtual Directory.

In the Add Virtual Directory dialog box, type a name in the Alias box. This alias is used to access the content from a URL.

In the Physical path box, type the physical path of the content folder, or click Browse to navigate through the file system to find the folder.

Optionally, click Connect as to specify credentials that have permission to access the physical path. If you do not use specific credentials, select the Application user (pass-thru authentication) option in the Connect As dialog box.

Optionally, click Test Settings to verify the settings that you specified for the virtual directory.

Click OK.

Command Line

To add a virtual directory to the root application in a site, use the following syntax:

appcmd add vdir / /path:string /physicalPath:string

The variable app.namestring is the site name and the / following the name specifies that the virtual directory should be added to the root application of the site. The variable pathstring is the virtual path of the virtual directory, such as /photos, and physicalPathstring is the physical path of the virtual directory’s content in the file system.

For example, to add a virtual directory named photos with a physical location of c:images to the root application in a site named contoso, type the following at the command prompt, and then press ENTER:

appcmd add vdir / /path:/photos /physicalPath:c:images

To add a virtual directory to an application other than a site’s root application, type the name of the application after / in app.namestring. For example, to add the same virtual directory used in the previous example to an application named marketing in a site named contoso, type the following at the command prompt, and then press ENTER.


How to make Apache run ASP.NET / ASP.NET 2.0

December 15, 2008 · Leave a Comment
Filed under: Apache, ASP, ASP.NET, ASP.NET 2.0, Featured 

Even worked with ASP.NET 2.0 Site !

Following are the instruction to make Asp.Net work under apache:

– Install Apache 2.0.54

– Install Mod_AspDotNet

– Add at the end of C:Program FilesApache GroupApache2confhttpd.conf the following lines
LoadModule aspdotnet_module “modules/”

AddHandler asax ascx ashx asmx aspx axd config cs csproj licx rem resources resx soap vb vbproj vsdisco webinfo

<IfModule mod_aspdotnet.cpp>
# Mount the ASP.NET /asp application
AspNetMount /SampleASP “c:/SampleASP”
#/SampleASP is the alias name for to execute
#”c:/SampleASP” is the actual execution of files/folders in that location

# Map all requests for /asp to the application files
Alias /SampleASP “c:/SampleASP”
#maps /SampleASP request to “c:/SampleASP”
#now to get to the /SampleASP type http://localhost/SampleASP
#It’ll redirect http://localhost/SampleASP to “c:/SampleASP”

# Allow scripts to be executed in the /SampleASP example
<Directory “c:/SampleASP”>
Options FollowSymlinks ExecCGI
Order allow,deny
Allow from all
DirectoryIndex index.htm index.aspx
#default the index page to .htm and .aspx

# For all virtual ASP.NET webs, we need the aspnet_client files
# to serve the client-side helper scripts.
AliasMatch /aspnet_client/system_web/(d+)_(d+)_(d+)_(d+)/(.*) “C:/Windows/Microsoft.NET/Framework/v$1.$2.$3/ASP.NETClientFiles/$4

<Directory “C:/Windows/Microsoft.NET/Framework/v*/ASP.NETClientFiles”>
Options FollowSymlinks
Order allow,deny
Allow from all

– Create a directory c:SampleASP and insert in it the index.aspx

– Restart apache server :
Start-> Apache HTTP Server 2.0.54 ->
Control Apache Server -> Restart

– Open Explorer and navigate to http://localhost/SampleASP/index.aspx

If everything worked fine you should get a nice page working.

— index.aspx —

<%@ Page Language=”VB” %>
<link rel=”stylesheet”href=”intro.css”>
<form action=”index.aspx” method=”post”>
<h3> Name: <input id=”Name” type=text>
Category: <select id=”Category” size=1>
<input type=submit value=”Lookup”>
<% Dim I As Integer
For I = 0 to 7 %>
<font size=”<%=I%>”> Sample ASP.NET TEST</font> <br>
<% Next %>