placeholder

W

Wee Bubba

2 questions please.

1) if i make a placeholder invisible or remove it programmatically
does that mean its contents wont get loaded. e.g. lets say i had a
heavy datagrid within the placeholder which took a few seconds to
load. if i made the placeholder invisible does that mean the grid
would not get loaded at all so the page would load quicker?

2) can you remove a placeholder programmatically?

thanks.
 
N

Natty Gur

Hi,

The control won't render to the client (Browser) but binding on the
server side would take place. So there will be performance improvement.
You can improve your performance if you won't create and bind your
control at all. Consider the following code :

System.Collections.ArrayList oArr = new System.Collections.ArrayList();
for(int i = 0; i< 11 ; i++)
{
oArr.Add("string " + Convert.ToString(i) );
}

ListBox o = new ListBox();
o.Visible = true;
o.DataSource = oArr;
o.DataBind();
PlaceHolder2.Controls.Add(o);

I create dynamic listbox and add it to Placeholder. I can remove place
holder programmatically:

this.FindControl("Form1").Controls.Remove(PlaceHolder2);

causing the datalist won't be render to the client. But I can use the
same condition and instead of removing place holder simply not to create
DatatList.

Natty Gur[MVP]

blog : http://weblogs.asp.net/ngur
Mobile: +972-(0)58-888377
 
J

Jos

Wee said:
2 questions please.

1) if i make a placeholder invisible or remove it programmatically
does that mean its contents wont get loaded. e.g. lets say i had a
heavy datagrid within the placeholder which took a few seconds to
load. if i made the placeholder invisible does that mean the grid
would not get loaded at all so the page would load quicker?

When you make it invisible:
the content gets loaded. The content will not be shown, but
its state will be added to viewstate.

When you remove it programmatically:
the content doesn't get loaded.
2) can you remove a placeholder programmatically?

Yes. In VB:
Page.Controls.Remove(Page.FindControl("IDofMyPlaceHolder"))
 
W

Wee Bubba

thanks guys. in my case i think i need to remove this programmatically
then becauser there's no point loading my contents if im not going to
display them.

thanks for the advice.
 

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

Top