Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > ASP .Net Web Controls > how to access PlaceHolder from codeBehind (class - .dll file) ???? PLEASE HELP

Reply
Thread Tools

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

 
 
gonzal kamikadze
Guest
Posts: n/a
 
      10-03-2005
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">
<asplaceHolder 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


 
Reply With Quote
 
 
 
 
nikki
Guest
Posts: n/a
 
      10-03-2005
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);

 
Reply With Quote
 
 
 
 
clintonG
Guest
Posts: n/a
 
      10-05-2005
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" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed) oups.com...
> 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);
>



 
Reply With Quote
 
Patrice
Guest
Posts: n/a
 
      10-05-2005
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" <(E-Mail Removed)> a écrit dans le message de
news:43412327$(E-Mail Removed)...
> 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">
> <asplaceHolder 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
>
>



 
Reply With Quote
 
nikki
Guest
Posts: n/a
 
      10-05-2005

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.

 
Reply With Quote
 
clintonG
Guest
Posts: n/a
 
      10-05-2005
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" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed) oups.com...
>
> 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.
>



 
Reply With Quote
 
 
 
Reply

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
Re: How include a large array? Edward A. Falk C Programming 1 04-04-2013 08:07 PM
Problem access usercontrol added to placeholder Anders K. Jacobsen [DK] ASP .Net 9 04-01-2005 07:10 PM
Build control in a placeholder or like a placeholder nail ASP .Net Building Controls 0 09-10-2004 07:57 PM
Linking HTMLTable to a CodeBehind variable?...Please help... Jay ASP .Net 2 07-22-2004 08:13 PM
please help... ...me learn C++ please please please :) KK C++ 2 10-14-2003 02:08 PM



Advertisments