views:

99

answers:

1

Is it required to call TemplateControl.ResolveUrl() before passing it to TemplateControl.LoadControl()?

Which way is preferred?

LoadControl(ResolveUrl("~/MyControl.ascx"));
LoadControl("~/MyControl.ascx");
LoadControl("MyControl.ascx");

or maybe ResolveClientUrl() ?

+3  A: 

It's not required. I wouldn't even recommend doing the first method, since it's just redundant and adds complexity. The tilde means it's relative to the application root already - ResolveUrl just changes it to be relative to the page or usercontrol you're calling it from. Either way, it will still be loaded.

The second way would be preferred as a best practice to help guard against relative structural changes to your project.

Even better would be to make the path string a resource or at least a constant to get rid of magic strings and avoid surprises altogether.

womp
To summarize: 2nd way
GoodEnough