Working with content areas in code behind

In my master page, I have a ContentPlaceHolder defined:


In the page, I have the content defined:

<asp:Content runat="server" ID="conTrackingScripts" ContentPlaceHolderID="AfterScripts">
    <!-- Blah -->

Unfortunately, this code does not work:

conTrackingScripts.Visible = false;

The error given is "The name 'conTrackingScripts' does not exist in the current context. A quick Google search shows that many others have had the same issue. The solution is to use the following code instead:

(Master as MasterPage).FindControl("AfterScripts").Visible = false;

Substitute the name of your master page for "MasterPage", and the name of your ContentPlaceHolder for "AfterScripts" in the above code

It appears that you cannot edit properties on the content, you have to edit the ContentPlaceHolder directly.

Like this post? Please share it!

See a mistake? Edit this post!

Using iStockPhoto to make your website awesome

The look of a website is key in determining the emotion that your visitors will feel when they look at it. For example, it's been proven that photos of people on your website will increase customer confidence, and lead to a higher sales conversion rate.


Traditionally stock imagery has been expensive to purchase, and time consuming to create. Many sites that I have seen simply steal images from other sites, or even hotlink in some cases.

I wanted to make sure my blog is using images that are legal, and I discovered iStockPhoto.

As of this writing, they have over 3 million images. The majority are extremely professional, and be just what it takes to give credibility to your website. I'm usually able to find a picture for each of my blog posts, which makes breaks up the content and makes it easier to read.

Here is a site for monitoring your position in a search engine, which I took the liberty of redesigning with some stock imagery.

Before: ugly

After: with stock photos

Like this post? Please share it!

See a mistake? Edit this post!

Disable constraints in "After Insert" trigger

I have a table that stores extra information (Users) that gets associated with the "aspnet_Membership" table in my application. Since my table references the membership table, I have a foreign key for referential integrity.

I added a trigger to the membership table so that rows automatically get inserted into my table. The problem is, the trigger violates the foreign key constraint! Here is the trigger code:

Create Trigger dbo.Trigger_CreateExtraUserRecord ON aspnet_Users
After Insert
    Set Nocount On
    Insert Into tfs_Users
    Select UserId From inserted

As you can see, it's an "After Insert" trigger, so the first insert will be done at this point (I have verified that).

It must be using some kind of transaction, and the foreign key is violated because it's not committed.

The solution (not perfect, but it works), is to use this before the insert to disable the foreign key check:

Alter Table tfs_Users Nocheck Constraint All

And use this after:

Alter Table tfs_Users Check Constraint All

Instead of disabling all constraints, you could also specify the constraint name, which would obviously be better in most cases.

Does anyone have a better explanation for this behavior?

Like this post? Please share it!

See a mistake? Edit this post!

Jason Young I'm Jason Young, software engineer. This blog contains my opinions, of which my employer - Microsoft - may not share.

@ytechieGitHubLinkedInStack OverflowPersonal VLOG