Get Help:Ask a Question in our Forums|Report a Bug|More Help Resources
Last post Aug 13, 2011 05:08 AM by Bryan Strader
Aug 11, 2011 06:20 PM|LINK
This code will return the file name of the user control, placed in the code behind of a user control. This can be useful when creating generic code that needs to know the name of the user control. By eliminating the need to hard code the file name into the
code behind, the file name can be renamed, copied, etc. without having to update the hard coded name. It effectively allows the control to ask the question Who Am I?. This should also work when you need the name of the current page. However it has not been
tested for that function.
This is different from the various techniques to get the file name of the PAGE (orders.aspx) in that it returns the FILE NAME of a USER CONTROL (MyInformation.ascx) in the event that the USER CONTROLS needs to know its own name.
test.Text = Me.AppRelativeVirtualPath.Replace (Me.AppRelativeTemplateSourceDirectory, "")
Protected Sub FormViewContactDetail_PreRender(ByVal sender As Object, ByVal e As System.EventArgs)
Searches:How do I get the filename of a user control? Get filename of a user control Get a user control's file name User control file name property filename of a ascx file code behind
Aug 13, 2011 05:08 AM|LINK
Explore the System.Reflection namespace, there are many items there to help get current assembly/class information.