![]() |
![]() | ![]() | ![]() | ![]() | ![]() | ![]() | ![]() |
| Welcome to Windows Vista Forums. Our forum is dedicated to helping you find solutions with any problems, errors or issues you are experiencing with Windows Vista. The Vista forum also covers news and updates and has an extensive Windows Vista tutorial section that covers a wide range of tips and tricks. |
| |||||||
![]() |
| |
| | #1 (permalink) |
| | Obtaining Correct Type with usage of ParseControl() 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 = "<asp:PlaceHolder ID=\"MyPH\" runat=\"server\"></asp:PlaceHolder>"; 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. |
My System Specs![]() |
| | #2 (permalink) |
| | Re: Obtaining Correct Type with usage of ParseControl() why use parse control for this? just create the control, its much better coding. var px = new System.Web.UI.WebControls.PlaceHolder(); px.ID = "MyPH"; this.Controls.Add(px); you original problem is parse control returns user control containing the placeholder as a child control. -- bruce (sqlwork.com) Jordan S. wrote: Quote: > 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 = "<asp:PlaceHolder ID=\"MyPH\" > runat=\"server\"></asp:PlaceHolder>"; > > 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. > > > |
My System Specs![]() |
| | #3 (permalink) |
| | Re: Obtaining Correct Type with usage of ParseControl() Thanks Bruce... the piece I was missing was that ParseControl returns a user control that in turn contains the PlaceHolder as a child. That's helpful to know. I'm using ParseControl for this because I have an HTML string that contains one or more PlaceHolder controls, and I was having difficulty getting to the correct collection. The shortened HTML snippet in the OP was just for the sake of brevity. Thanks again. "bruce barker" <nospam@xxxxxx> wrote in message news:O3mwOhsHJHA.1160@xxxxxx Quote: > why use parse control for this? just create the control, its much better > coding. > > var px = new System.Web.UI.WebControls.PlaceHolder(); > px.ID = "MyPH"; > this.Controls.Add(px); > > you original problem is parse control returns user control containing the > placeholder as a child control. > > -- bruce (sqlwork.com) > > > Jordan S. wrote: Quote: >> 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 = "<asp:PlaceHolder ID=\"MyPH\" >> runat=\"server\"></asp:PlaceHolder>"; >> >> 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. >> >> >> |
My System Specs![]() |
![]() |
| Thread Tools | |
| |
Similar Threads | ||||
| Thread | Forum | |||
| Sleep mode correct usage? | General Discussion | |||
| auto-correct as you type | Vista mail | |||
| Obtaining RC2 | Vista General | |||
| Obtaining a new key | Vista General | |||