HtmlMeta Class

Namespace: System.Web.UI.HtmlControls

private void AddMetaRefresh()
{
HtmlMeta metaValue = null;

metaValue = new HtmlMeta();
metaValue.Attributes.Add(”http-equiv”, “refresh”);
metaValue.Attributes.Add(”content”, Settings.AutoRefreshInterval.ToString());

this.Page.Header.Controls.Add(metaValue);
}

App_GlobalResources maps to a directory outside this application, which is not supported.

Problem

I’ve created a very simple ASP.NET 2.0 application. I can run this with no problems using the Built-in Web Server. However, if I publish it and try running the application by typing
http://localhost/talentdata/default.aspx directly in the browser window, I get the following error:
Server Error in ‘/talentdata’ Application.
The path ‘/talentdata/App_GlobalResources’ maps to a directory outside this application, which is not supported.

Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.Web.HttpException: The path ‘/Beta2_TEST/App_GlobalResources’ maps to a directory outside this application, which is not supported.

Solution

The solution is quite simple. I checked the IIS Default Web Site Properties -> Home Directory -> Local Path. Don’t add any “\” character at the end of the directory, so I changed the Local Path to “C:\Inetpub\wwwroot” instead of “C:\Inetpub\wwwroot\” and restarted IIS.

IIS will automatically add one thus cause problem if you manually add one before. You can check Default Web Site Properties -> ASP.NET -> File Location for actual setting information.

Gridview - Getting the RowIndex

The following syntax sets the rowindex equal to the specific row number:

int rowindex = ((GridViewRow)((Control)e.CommandSource).Parent.Parent).RowIndex;

How to access the EmptyDataTemplate controls from OnRowCommand in GridView

For example - inserting value in the empty gridview:

protected void GridView1_RowCommand(object sender, GridViewCommandEventArgs e)
{
if (e.CommandName == “Insert”) {
TextBox txt =
(((Control)e.CommandSource).NamingContainer).FindControl(”txtTest”) as TextBox;

//do insert action
}
}

Another way to do this is by getting EmptyDataTemplate table and its controls:

if (e.CommandName == “Insert”)

{
Table table = (Table)GridView1.Controls[0];
TextBox txtTest= (TextBox)table.Rows[0].FindControl(”txtTest”);

//do insert actions
}

Error while trying to run project: Unable to start debugging on the web server

Open your Internet Information Services manager and from the [your machine]/Web Sites/ Default Web Site node select the virtual folder which stores your project. Right Click and select Properties to select the ASP.NET tab page. Make sure the correct version ASP.NET Version is selected.

I have VS.NET 2003 and 2005 beta 1 running side-by-side on my box and noticed ASP.NET Version 2.0 is targeted by default, even for VS.NET 2003 projects.

Change datagrid cell properties

///C#

public void dgBoundItems(object sender, DataGridItemEventArgs e)
{
foreach(TableCell cell in e.Item.Cells)
{
///e.Item.DataSetIndex = row
///e.Item.Cells.GetCellIndex(cell) = column

if (e.Item.Cells.GetCellIndex(cell) == 2 && e.Item.DataSetIndex > 0)
{
///If the salary is less than 5000 the color must be red.
if (Convert.ToInt32(cell.Text.Trim()) < 5000)
{
cell.ForeColor = Color.Red;
}
}
}
}

Inline IF’ Statement

The syntax is “myInt = (<condition> ? <true value> : <false value>)”

DateTime Format String

DateTime now = new DateTime(2006, 9, 07, 15, 06, 01, 08, DateTimeKind.Local);

now.ToString(); //”09/27/2006 15:06:01″

Year

now.ToString(”%y”); //”6″

now.ToString(”yy”); //”06″

now.ToString(”yyy”); //”2006″

now.ToString(”yyyy”); //”2006″

Month

now.ToString(”%M”); //”9″

now.ToString(”MM”); //”09″

now.ToString(”MMM”); //”Sep”

now.ToString(”MMMM”); //”September”

Day

now.ToString(”%d”); //”7″

now.ToString(”dd”); //”07″

now.ToString(”ddd”); //”Thu”

now.ToString(”dddd”); //”Thursday”

Hour

now.ToString(”%h”); //”3″

now.ToString(”hh”); //”03″

now.ToString(”hhh”); //”03″

now.ToString(”hhhh”); //”03″

now.ToString(”%H”); //”15″

now.ToString(”HH”); //”15″

now.ToString(”HHH”); //”15″

now.ToString(”HHHH”); //”15″

Minutes

now.ToString(”%m”); //”3″

now.ToString(”mm”); //”03″

now.ToString(”mmm”); //”03″

now.ToString(”mmmm”); //”03″

Seconds

now.ToString(”%s”); //”1″

now.ToString(”ss”); //”01″

now.ToString(”sss”); //”01″

now.ToString(”ssss”); //”01″

Milliseconds

now.ToString(”%f”); //”0″

now.ToString(”ff”); //”00″

now.ToString(”fff”); //”008″

now.ToString(”ffff”); //”0080″

now.ToString(”%F”); //”"

now.ToString(”FF”); //”"

now.ToString(”FFF”); //”008″

now.ToString(”FFFF”); //”008″

Kind

now.ToString(”%K”); //”-07:00″

now.ToString(”KK”); //”-07:00-07:00″

now.ToString(”KKK”); //”-07:00-07:00-07:00″

now.ToString(”KKKK”); //”-07:00-07:00-07:00-07:00″

(Source)

Problems with MagicAjax

I added what is below to my web.config file:

<httpModules>
<add name=”MagicAjax” type=”MagicAjax.MagicAjaxModule, MagicAjax”/>
<add name=”ScriptModule” type=”Microsoft.Web.Services.ScriptModule”/>
</httpModules>

And I got:

Could not load file or assembly ‘MagicAjax’ or one of its dependencies.
The system cannot find the file specified. (C:\Inetpub\wwwroot\TheTracker\web.config line 48)

The solution I found that worked was adding the MagicAjax assembly
is in your /bin folder. And that fixed the problem.

Console Applications

Console Applications are command-line oriented applications that allow us to read characters from the console, write characters to the console and are executed in the DOS version. Console Applications are written in code and are supported by the System.Console namespace.

(Source)


Hello World - Console Application