Re: System.Type.GetType();

Tech Tip: Click here to run a free scan for Windows Errors and optimize PC performance

From: Scott Allen (bitmask_at_[nospam)
Date: 09/17/04


Date: Thu, 16 Sep 2004 23:31:40 -0400

Hi Josh:

I'm not sure what you are trying to do exactly by looking at the code
excerpt, or what is going wrong (is there an exception or error
message?). However, I strongly suspect you don't want to be using
Type.GetType and Activator.CreateInstance. If you just pass the ascx
file name to Page.LoadControl you'll get back a reference to a user
control that is instantiated and ready to be placed on a page. As it
stands it looks like you are discarding this reference.

--
Scott
http://www.OdeToCode.com
On Fri, 17 Sep 2004 10:22:48 +1000, "Josh"
<josh@rb.com.auREMOVETOEMAIL> wrote:
>Hi Guys,
>I have hit a wall with the my project... The problem is that i need to get 
>the type of a usercontrol that is not in the assembly of the page that is 
>tryiong to call it. if anyone knows of how to fix this please let me know.
>
>c.setComponentProperties(Request.QueryString["pageID"],"1");
>classname = c.cSrc;
>t = System.Type.GetType(classname);
>uc = (UserControl)Activator.CreateInstance(t);
>ctl = 
>uc.LoadControl(System.Configuration.ConfigurationSettings.AppSettings["virtualPath"]
>+ classname.Substring(classname.LastIndexOf(".") + 1) + ".ascx");
>
>t.GetProperty("ComponentID").SetValue(ctl,c.cID.ToString(),null);
>PlaceHolder phPlaceHolder1 = 
>(PlaceHolder)this.FindControl("Form1").FindControl("PlaceHolder1");
>phPlaceHolder1.Controls.Clear();
>phPlaceHolder1.Controls.Add(ctl);
>string mode = "edit";
>litContentBegin.Text = "<div id=\"con\" 
>onMouseOver=\"showEditableArea(this);\" 
>onMouseOut=\"hideEditableArea(this);\" 
>onClick=\"editComponent('../siteadmin/components.aspx?mode=" + mode + 
>"&placeholderID=" + "1" + "&pageID=" + 
>Request.QueryString["pageID"].ToString() + "');\">";
>litContentEnd.Text = "</div>";
>
>Thanks
>Josh 
>


Relevant Pages

  • Re: Dataset retunring Null ..a gurus opinion required!
    ... How is estateOleAdapter initialized? ... toolbox to the design area to establish the connection. ... application this exception comes up): ... When adding a reference, I tried "Add Service Reference" and I also ...
    (microsoft.public.dotnet.framework.aspnet.webservices)
  • Re: "invalid handle", sockets, threads and garbage collector
    ... your IntPtr value happens to coincide with a reference. ... The exception contains "invalid handle" message. ... Socket constructor problem ... finalization means closing the handle to resource. ...
    (microsoft.public.dotnet.framework.clr)
  • Global Assembly Cache Issue
    ... I have a dll that I use in several projects, that I placed in the Global ... you can see in the Exception below). ... If I change the Copy Local property of the reference to True, ... Attempting download of new URL ...
    (microsoft.public.dotnet.framework.aspnet)
  • Re: newbie: deactivate query before freeing?
    ... but the exception will still be thrown. ... There is exactly one invalid reference, the null pointer, nil. ... abort the normal flow of execution and start handling the exception ...
    (comp.lang.pascal.delphi.misc)
  • Re: PowerPoint shapeId/ShapeName property changes/Increments autom
    ... I agree with what u r saying, reference is stored in a shape type variable ... which result in a com exception in my code. ... >> I am posting a small sample code to better explain my problem ... >> Sub Testing() ...
    (microsoft.public.office.developer.vba)