.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
Sign In
Win Surprise Gifts!!!

Top 5 Contributors of the Month
Post New Web Links

TypeOf/getType ?

Posted By:      Posted Date: October 08, 2010    Points: 0   Category :ASP.Net

Hi there,

I have added a few WebUserControl's to a form and I want to check their properties values in a code behind (vb) when a user click a button.

I tried unsuccessfully to get a reference to these controls using the TypeOf and GetType functions...

How do I get a reference to the webUserControls ?

View Complete Post

More Related Resource Links

BuildManager.GetType returns null until application pool recycles

Our application uses the Enterprise Library's PropertyProxyValidator class to validate user input (v4.1 - Oct 2008).  On occassion, the code will raise an exception saying the source type cannot be found.  This error persists until the application pools recycle at night, at which point everything works again.  It tends to only affect one of the web front ends at a time (there are two). I tracked down where the exception was being raised, and this is the section of code:Type IValidationIntegrationProxy.ValidatedType { get { if (string.IsNullOrEmpty(this.sourceTypeName)) { throw new InvalidOperationException(Resources.ExceptionNullSourceTypeName); } Type validatedType = BuildManager.GetType(this.SourceTypeName, false, false); if (validatedType == null) { throw new InvalidOperationException( string.Format(CultureInfo.CurrentUICulture, Resources.ExceptionInvalidSourceTypeName, this.sourceTypeName)); } return validatedType; } } (As you can see, the value for this.SourceTypeName is shown in the exception and I've checked that it matches exactly.) We have never been able to reproduce this exception and at this point don't have any ideas left as far as causes.  For a while, my suspicion was that it was related to the Temporary ASP.NET Files folder.  The last

How Do I Not Include: myControl.GetType.GetProperty("Text") When No Property Window Setting?

Hi All, Posted below is code I'm using to generate a list of controls that have either a "Text" or "Caption" property. However, for certain controls in the resulting list, the property setting (Text/Caption) does not appear in the "Property Window" of the IDE when that control is selected. One example of this is the Systems.Windows.Forms.PictureBox control. Is there a way I can determine this and if so - how do I exclude these control(s) from my list?     Private Sub cmdValidateControls_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdValidateControls.Click         txtResults.Clear()         For Each ctrl As Object In Me.Controls             LogControl(ctrl)         Next     End Sub     Private Sub LogControl(ByVal ctrlIn As Object)         If System.Diagnostics.Debugger.IsAttached Then             If (Not ctrlIn.GetType.GetProperty("Text") Is Nothing) Or (Not ctrlIn.GetType.GetProperty("Caption") Is Nothing) Then                 txtRes

Features of ToString() and GetType()

Write about the features of the above two methods in C#? I need some features of the above methods to complete my exam preparation.

An object reference is required for the nonstatic field, method, or property 'object.GetType()'


I'm getting this error, what i'm missing?

error: An object reference is required for the nonstatic field, method, or property 'object.GetType()'


static public void RegisterScriptMethod(System.Web.UI.Page page, string methodName, string methodBody)


StringBuilder sb = new StringBuilder();


"<script language='javascript'>");


"function " + methodName + " {" + methodBody + "}");



//page.RegisterClientScriptBlock(methodName, sb.ToString());

C# typeof


Hi guys,

Have this code that works fine:

        ObjectHandle reportManagerObject = Activator.CreateInstance(typeof(LABReportManager).Assembly.FullName.ToString(), "eAppForm.Reporting.LABReportManager");
        IReportManager reportManager = (IReportManager)reportManagerObject.Unwrap();        
        reportManager.GetReportFileName(null, "yes", "");

        ObjectHandle reportManagerObject = Activator.CreateInstance(typeof(MyReportManager).Assembly.FullName.ToString(), "Reporting.MyReportManager");

        IReportManager reportManager = (IReportManager)reportManagerObject.Unwrap();        

        reportManager.GetReportFileName(null, "yes", "");

This creates an instance of the MyReport

using typeof for a reference type


namespace AssemblyA
    public class Product
        private int cinProductID;
        public int ProductID
            get { return cinProductID; }
            set { cinProductID = value; }

        private Array csCategoryName;
        public Array CategoryName
            get { return csCategoryName; }
            set { csCategoryName = value; }

namespace AssemblyA
    public class Categories
        private string csName;
        public string Name

Type myType = a.GetType("Class1"); returns NULL

I created a class Class1 and generated a strong named assembly. Following is my simple class. But when i try to load this assembly using 
Assembly.Load() - > Type.GetType() returns null. Cannot figure out why? Below is the code for Assembly.Load
namespace LoadAssemblyTest
    public class Class1
        public void GetDriveInfo()
            Console.WriteLine("Drives: ");
            foreach (DriveInfo di in DriveInfo.GetDrives())
                Console.WriteLine(" {0} ({1}) ", di.Name, di.IsReady);

            Console.WriteLine("Press the drive letter to view the folder: ");
            ConsoleKeyInfo drive = Console.ReadKey(true);
            DirectoryInfo dir = new DirectoryInfo(drive.Key.ToString() + @":\");
            foreach (DirectoryInfo dirInfo in dir.GetDirectories())
                Console.WriteLine("\n " + dirInfo.FullName);

            Console.WriteLine("Press \'q\' to quit the sample.");
            while (Console.Read() != 'q') ;



How object.GetType() works?



What object.GetType method does to determine the actual type at runtime? I'vea method that takes an object[] array. The array holds entities of different types, e.g, Product and Order.

object[] items = new object[2];
items[0] = new Product();
items[1] = new Order();

Now I am calling this code:


It gives me the exact type information which is Product in this instance. Can anybody explain me how object.GetType resolves the exact type at runtime?

Some questions about Assembly.GetType() under the Turky locale


I writ the follwing test case in VS2008 to test the behavior of Assembly.GetType() under the Turky locale.

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Reflection;
using System.Threading;
using System.Globalization;

namespace MyTest
  class Program
    static void Main(string[] args)
      //Thread.CurrentThread.CurrentCulture = new CultureInfo("en-US");
      Thread.CurrentThread.CurrentCulture = new CultureInfo("tr-TR");

      string n1 = "MyTest.i";
      string n2 = "MyTest.I";
      string n3 = "MyTest.i&quo
ASP.NetWindows Application  .NET Framework  C#  VB.Net  ADO.Net  
Sql Server  SharePoint  Silverlight  Others  All   

Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend