Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 610647
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T17:41:52+00:00 2026-05-13T17:41:52+00:00

I have a UserControl (lets say Foo.ascx) that has a Type public property with

  • 0

I have a UserControl (lets say Foo.ascx) that has a Type public property with the name Bar.
I am looking for a way that when i declare this usercontrol in the source view of the markup part to pass a type. for example

<%@ Register Src="~/Controls/Foo.ascx" TagPrefix="prfx" TagName="fooCtrl" %>

and then use it as

<prfx:fooCtrl ID="theId" runat="server" />

if for example i wanted to pass to the control the type of string (such as typeof(string))
something that would have this effect

<prfx:fooCtrl ID="theId" runat="server" Bar="typeof(string)" />

how can it be done?
Before anyone asks, the reason is that i have many other properties in this usercontrol that i pass in this manner and i want to avoid using the CodeBehind just to pass the Type

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-13T17:41:53+00:00Added an answer on May 13, 2026 at 5:41 pm

    Short answer, you can’t do this. The editor and compiler treats .ascx files as (in the end) XML. That means on “deserialization” properties can be converted to various primitive types but not complex types such as System.Type. To work, what you would like to do would require, at some point during compilation, that an attribute in an xml document not be treated as text, not converted to a simple type, but interpreted and executed as code. Without altering how Visual Studio and the ASP.NET compiler works, this won’t happen.


    Workaround:

    1. Create a public property of type string in your UserControl
    2. Pass the AssemblyQualifiedName of the type you wish to pass to the UserControl via this attribute
    3. Use the GetType(string) overload to get an instance of this type within your code.

      <prfx:fooCtrl
      ID=”theId”
      runat=”server”
      Bar=”System.String, mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089″ />

    and, in code:

    /* ... */
    var barType = Type.GetType(this.Bar);
    // do whatever you want with this type
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a UserControl in my Asp.net project that has a public property. I
I have a user control named lets say ucName that has a property named
Lets say i have this usercontrol public class test : UserControl { public int
I have a usercontrol that has several public properties. These properties automatically show up
Lets say that I have a header user control in a master page, and
Let's say you have two classes that extend UserControl . Each of the controls
so I have this UserControl that's inside of another UserControl. Lets call them ParentUC
Lets say I have a custom control (child of System.Windows.Forms.UserControl) such as a graph.
I have UserControl which has two components public System.Windows.Forms.ComboBox innerComboBox; public System.Windows.Forms.TextBox innerTextBox; and
Let's pretend I have the following xaml... <UserControl.Resources> <local:ViewModel x:Name=viewModel /> <local:LoadChildrenValueConverter x:Name=valueConverter />

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.