Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > Re: Obtaining Correct Type with usage of ParseControl()

Thread Tools

Re: Obtaining Correct Type with usage of ParseControl()

bruce barker
Posts: n/a
why use parse control for this? just create the control, its much better

var px = new System.Web.UI.WebControls.PlaceHolder();
px.ID = "MyPH";

you original problem is parse control returns user control containing
the placeholder as a child control.

-- bruce (

Jordan S. wrote:
> The following 3 lines of code exist in a user control (Page_Load). Line 3
> chokes with the following exception message: "Unable to cast object of type
> 'System.Web.UI.Control' to type 'System.Web.UI.WebControls.PlaceHolder'."
> Why is this? How can I get a proper "PlaceHolder" reference to ctl?
> line1: string sTemp = "<asplaceHolder ID=\"MyPH\"
> runat=\"server\"></asplaceHolder>";
> line2: Control ctl = this.ParseControl(sTemp);
> line3: System.Web.UI.WebControls.PlaceHolder px =
> (System.Web.UI.WebControls.PlaceHolder)ctl;
> fwiw: I'm using .NET 3.5.
> Thanks.

Reply With Quote

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
help - obtaining the type of the object usingtp_name Mrinalini Kulkarni Python 0 12-25-2011 11:28 AM
Obtaining class instance of generic quantified type Rakesh Java 4 04-24-2008 07:43 PM
Obtaining column type in OCI8 Sean Nakasone Ruby 1 11-11-2007 03:34 AM
Obtaining column type in Oracle table Sean Nakasone Perl Misc 1 11-08-2007 12:53 PM
casting primitive type to user-defined type works in usage C++ 2 04-15-2006 05:37 AM