Can't add to placeholder

G

Guest

Hi,

using vb.net 1.1

I am trying to add a control to a placeholder but am having problems with it.

I do it practically the same way as i do in C# (I have more C# skill than
VB.NET)and I have asked someone with more VB experience to look at it and
they can't see why it fails.

Any help appreciated...

Dim DocRSSLiteral As New Literal
DocRSSLiteral.Text = "<link href=""" & po.DisplayPath & """
rel=""alternate"" type=""application/rss+xml"" title=""" & po.DisplayName &
""" />"

RSSPlaceHolder.Controls.Add(DocRSSLiteral)

It is failing on the PlaceHolder Controls.Add line.

I can remove all these lines, try and add a label or a hyperlink and they
fail in exactly the same way.

Thanks for your help.

Regards,
Dave Colliver.
http://www.AshfieldFOCUS.com
~~
http://www.FOCUSPortals.com - Portal franchises available
 
G

Guest

Sorry, forgot to say what the error was...

Object reference not set to an instance of an object

The placeholder is on the page and has been inserted into the Web Form
Designer Generated Code region.

As you can see, the object I am trying to add to the control is also declared.

Regards,
Dave Colliver.
http://www.AshfieldFOCUS.com
~~
http://www.FOCUSPortals.com - Portal franchises available
 
J

JosephByrns

Your code works fine here, are you sure that it is not po that is nothing?
Is po being properly declared?

Have you tried replacing DocRSSLiteral.Text = "...." with DocRSSLiteral.Text
= "TEST" to see if that works?

Other than that I have no idea.
 
H

Hans Kesting

Apparently the RSSPlaceHolder is null.
This can happen if the Control *is* declared in codebehind (as
"protected", in C# terms), but there is no
<asp:placeHolder ID="RSSPlaceHolder" runat="server" />
in the aspx/ascx code. The ID value *must* match the name of the
control in codebehind and you *need* the runat=server attribute.

Another way this can happen: the codebehind is derived from some
specific baseclass where you declare that placeholder and work with it.
If you switch to design view, that declaration is added to the derived
codebehind class (the compiler will issue warnings about this
declaration hiding declarations from the baseclass)

Hans Kesting
 
G

Guest

Hi,

The placeholder is declared in my aspx. The declaration is below...
<asp:placeHolder id=RSSPlaceHolder runat="server"></asp:placeHolder>

This automatically added...
Protected WithEvents RSSPlaceHolder As System.Web.UI.WebControls.PlaceHolder

to the codebehind. The codebehind is not being derived from any base class,
just System.Web.UI.Page.

To the other poster... Joseph, po is set else the code will fail where po is
used.
I actually remarked the line that uses po out and used a label which doesn't
have any variables, just text, tried to add the label and go the same prob
with that...

With what you are saying, the code should work, but it isn't working for me.
:-(

Regards,
Dave Colliver.
http://www.ManchesterFOCUS.com
~~
http://www.FOCUSPortals.com - Portal franchises available
 
G

Guest

This is getting weirder...

I have placed a label direct into the aspx and changed its text property to
display "Dave". I have run the page and no label.

I rebuilt the project and still no "Dave".

The label has appeared in the code behind. In the page load, I am
response.writing the label.text. When I do this, I get "Object reference not
set to an instance of an object".

I am using Microsoft CMS. It appears that the page has no reference to the
code behind or somehow the page has become disconnected, or the page itself
is cached as an object and that the codebehind just doesn't know what to do,
even though adding objects to the aspx drops the associated line in the
codebehind.

I have inherited this project, so am a little unsure of exactly what is
happening. I would appreciate some communication guiding me what to look for.

Regards,
Dave Colliver.
http://www.AshfieldFOCUS.com
~~
http://www.FOCUSPortals.com - Portal franchises available
 
G

Guest

Found it.

This is a project I have inherited. It uses Microsoft CMS, which has a
template system.

The template system can reference ANY aspx page, and of course, ASPX has a
codebehind, but the codebehind gets compiled into a DLL, which means that
theoretically, you can have just one code behind service many aspx pages if
the pages are very similar.

So, that is what had happened. One code behind was servicing many pages. In
visual studio, you can't normally have seperate pages/codebehinds. However,
the aspx had been "Exclude from project", meaning it didn't need the
codebehind, but the page when requested will still call the DLL, and of
course, when searching the solution for the page, as it is not part of the
project, it will not be found.

Just thought I would post this for completion.

Regards,
Dave Colliver.
http://www.LeedsFOCUS.com
~~
http://www.FOCUSPortals.com - Portal franchises available
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,582
Members
45,065
Latest member
OrderGreenAcreCBD

Latest Threads

Top