Re: Obtaining Correct Type with usage of ParseControl()

Discussion in 'ASP .Net' started by bruce barker, Sep 25, 2008.

  1. bruce barker

    bruce barker Guest

    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:
    > 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.
    >
    >
    >
     
    bruce barker, Sep 25, 2008
    #1
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Matthias Lohrer

    Page.ParseControl drives me crazy

    Matthias Lohrer, Jul 8, 2003, in forum: ASP .Net
    Replies:
    0
    Views:
    1,751
    Matthias Lohrer
    Jul 8, 2003
  2. Matthias Lohrer

    Using Validation Controls with Page.ParseControl

    Matthias Lohrer, Jul 29, 2003, in forum: ASP .Net
    Replies:
    1
    Views:
    1,596
    Satish Appasani
    Jul 29, 2003
  3. Chris Simeone

    .NET ParseControl() method problem

    Chris Simeone, Dec 10, 2003, in forum: ASP .Net
    Replies:
    0
    Views:
    2,354
    Chris Simeone
    Dec 10, 2003
  4. Jeremy McPeak

    ParseControl()

    Jeremy McPeak, Dec 21, 2003, in forum: ASP .Net
    Replies:
    1
    Views:
    1,918
    Rick Strahl [MVP]
    Dec 21, 2003
  5. Jordan S.
    Replies:
    1
    Views:
    407
    Jordan S.
    May 23, 2008
Loading...

Share This Page