Handling tilde (~) paths in ASCX correctly using ParseControl

Using ParseControl to load ASCX files stored as EmbeddedResource, I found that tilde paths (“~” denoting app root) were not interpreted to mean application root, but were left unchanged in markup attributes.

The solution is to set the AppRelativeTemplateSourceDirectory member variable of the loading control:

Control userControl = page.ParseControl(content);
this.AppRelativeTemplateSourceDirectory =
    userControl.AppRelativeTemplateSourceDirectory;
this.Controls.Add(userControl);

1 thought on “Handling tilde (~) paths in ASCX correctly using ParseControl

  1. Pingback: Series: ASP.Net User Control Libraries « devioblog

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.