how to access PlaceHolder from codeBehind (class - .dll file) ???? PLEASE HELP

Discussion in 'ASP .Net Web Controls' started by gonzal kamikadze, Oct 3, 2005.

  1. Hi

    It is possible to access a placeHolder in a aspx page from a class (compiled
    code)?
    (coding in VB)


    --- ASPX page ---
    <%@ Page Language="VB" ContentType="text/html" ResponseEncoding="iso-8859-1"
    debug="true" %>
    <%@ Import Namespace="myNameSpace" %>
    <script runat="server">
    Sub page_Load()
    Dim myClass As New testClass
    myClass.testSub
    End Sub
    </script>
    <html>
    <title>test page</title>
    <body>
    <form ID="form1" runat="server">
    <asp:placeHolder ID="plhTest" runat=server" />
    </form>
    </body>
    </html>



    --- page.vb ---
    Imports system
    Imports System.Web.UI
    Imports System.Web.UI.WebControls
    Imports System.Web.UI.HtmlControls

    Namespace myNameSpace
    Public Class testClass
    Inherits Page
    Public plhTest as PlaceHolder

    Sub testSub()
    Dim myLabel As New Label
    myLabel.Text = " - TEST LABEL - "
    plhTest.Controls.Add(myLabel)
    End Sub
    End Class
    End Namespace



    I'm getting all the time an error message like this:
    System.NullReferenceException: Object reference not set to an instance of an
    object.

    does anybody know the solution to the above problem??? thanks

    regards
    gonzal kamikadze, Oct 3, 2005
    #1
    1. Advertising

  2. gonzal kamikadze

    nikki Guest

    Sure it's possible. You are declaring it, but I don't see FindControl
    or a check that it exists anywhere...
    You need to do FindControl.

    Relevant snippets from my C# app...
    Control placeholder = this.FindControl("legacyPlaceholder");
    ....
    placeholder.Controls.Add(h);
    nikki, Oct 3, 2005
    #2
    1. Advertising

  3. gonzal kamikadze

    clintonG Guest

    FindControl is late bound and imposes performance penalties.
    An early bound approach would use a public property.

    That allows the objects to be initialized by the Page class at runtime which
    makes it easy for us to simply refer to merhods or properties using dotted
    grammar from Page_Load or wherever.

    I'm just about mastering this myself and only use FindControl at design-time
    and then try to refactor the code manually. Next on the learning curve is to
    learn how to use Visual Studio to refactor the code which is a feature I'm
    fairly certain Visual Studio supports. At least for C#.


    <%= Clinton Gallagher
    METROmilwaukee (sm) "A Regional Information Service"
    NET csgallagher AT metromilwaukee.com
    URL http://metromilwaukee.com/
    URL http://clintongallagher.metromilwaukee.com/




    "nikki" <> wrote in message
    news:...
    > Sure it's possible. You are declaring it, but I don't see FindControl
    > or a check that it exists anywhere...
    > You need to do FindControl.
    >
    > Relevant snippets from my C# app...
    > Control placeholder = this.FindControl("legacyPlaceholder");
    > ...
    > placeholder.Controls.Add(h);
    >
    clintonG, Oct 5, 2005
    #3
  4. gonzal kamikadze

    Patrice Guest

    For now my guess is that the variable is not considered as being a match for
    the control markup (try perhaps "protected" instead of "public").

    --
    Patrice

    "gonzal kamikadze" <> a écrit dans le message de
    news:43412327$...
    > Hi
    >
    > It is possible to access a placeHolder in a aspx page from a class

    (compiled
    > code)?
    > (coding in VB)
    >
    >
    > --- ASPX page ---
    > <%@ Page Language="VB" ContentType="text/html"

    ResponseEncoding="iso-8859-1"
    > debug="true" %>
    > <%@ Import Namespace="myNameSpace" %>
    > <script runat="server">
    > Sub page_Load()
    > Dim myClass As New testClass
    > myClass.testSub
    > End Sub
    > </script>
    > <html>
    > <title>test page</title>
    > <body>
    > <form ID="form1" runat="server">
    > <asp:placeHolder ID="plhTest" runat=server" />
    > </form>
    > </body>
    > </html>
    >
    >
    >
    > --- page.vb ---
    > Imports system
    > Imports System.Web.UI
    > Imports System.Web.UI.WebControls
    > Imports System.Web.UI.HtmlControls
    >
    > Namespace myNameSpace
    > Public Class testClass
    > Inherits Page
    > Public plhTest as PlaceHolder
    >
    > Sub testSub()
    > Dim myLabel As New Label
    > myLabel.Text = " - TEST LABEL - "
    > plhTest.Controls.Add(myLabel)
    > End Sub
    > End Class
    > End Namespace
    >
    >
    >
    > I'm getting all the time an error message like this:
    > System.NullReferenceException: Object reference not set to an instance of

    an
    > object.
    >
    > does anybody know the solution to the above problem??? thanks
    >
    > regards
    >
    >
    Patrice, Oct 5, 2005
    #4
  5. gonzal kamikadze

    nikki Guest

    clintonG wrote:
    > FindControl is late bound and imposes performance penalties.


    Really?
    What kind?
    Under what situations is it a bad thing to use?
    Any articles you could point me to?

    Thx.
    nikki, Oct 5, 2005
    #5
  6. gonzal kamikadze

    clintonG Guest

    To start getting insight into this topic...
    google: late bound vs early bound asp.net performance

    There's much I need to learn myself.

    <%= Clinton Gallagher
    METROmilwaukee (sm) "A Regional Information Service"
    NET csgallagher AT metromilwaukee.com
    URL http://metromilwaukee.com/
    URL http://clintongallagher.metromilwaukee.com/




    "nikki" <> wrote in message
    news:...
    >
    > clintonG wrote:
    >> FindControl is late bound and imposes performance penalties.

    >
    > Really?
    > What kind?
    > Under what situations is it a bad thing to use?
    > Any articles you could point me to?
    >
    > Thx.
    >
    clintonG, Oct 5, 2005
    #6
    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. Anushi
    Replies:
    5
    Views:
    8,630
  2. Jay
    Replies:
    2
    Views:
    615
  3. KK
    Replies:
    2
    Views:
    522
    Big Brian
    Oct 14, 2003
  4. nail

    Build control in a placeholder or like a placeholder

    nail, Sep 10, 2004, in forum: ASP .Net Building Controls
    Replies:
    0
    Views:
    321
  5. H. Simpson
    Replies:
    4
    Views:
    244
    H. Simpson
    Aug 3, 2004
Loading...

Share This Page