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);

One Response to Handling tilde (~) paths in ASCX correctly using ParseControl

  1. […] Handling tilde (~) paths in ASCX correctly using ParseControl […]

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 )

Twitter picture

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

Facebook photo

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

Google+ photo

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

Connecting to %s

%d bloggers like this: