473,396 Members | 2,082 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

ASP PlaceHolder control

I have an ASP:Placeholder and I'm trying to populate with Label
controls from the code behind after a button click, essentially
creating a list of selections. But each time I click the button, it's
replacing the label in the placeholder rather than appending to it.

Is this the way the Placeholder control is supposed to work or is there
a way around this?

protected void btnApplyFilter_Click(object sender, EventArgs e)
{
Label lblAttribute = new Label();
lblAttribute.Text = ddlAttribute.SelectedItem.ToString() + ":";
lblAttribute.CssClass = "textGrey10";
phAttribute.Controls.Add(lblAttribute);

Label lblValue = new Label();
lblValue.Text = ddlValue.SelectedItem.ToString();
lblValue.CssClass = "textGrey10";
phValue.Controls.Add(lblValue);
}

<table border="0" cellpadding="0" cellspacing="0" width="100%">
<tr>
<td align="left">
<asp:Label ID="lblFilterHeader" runat="server" Text="Please select a
report filter" CssClass="textGrey10" />
</td>
</tr>
<tr>
<td align="left">
<asp:DropDownList ID="ddlAttribute" runat="server"
CssClass="textGrey10"
OnSelectedIndexChanged="ddlAttribute_SelectedIndex Changed"
AutoPostBack="true">
<asp:ListItem Text="" Value="" />
<asp:ListItem Text="Model" Value="Model" />
<asp:ListItem Text="Name" Value="Name" />
<asp:ListItem Text="Item Type" Value="Item Type" />
<asp:ListItem Text="Vendor" Value="Vendor" />
<asp:ListItem Text="Location" Value="Location" />
<asp:ListItem Text="Department" Value="Department" />
<asp:ListItem Text="Description" Value="Description" />
<asp:ListItem Text="Work Authorization" Value="Work Authorization"
/>
<asp:ListItem Text="PO Date" Value="PO Date" />
<asp:ListItem Text="Warranty Expires" Value="Warranty Expires" />
<asp:ListItem Text="Invoice Number" Value="Invoice Number" />
<asp:ListItem Text="Invoice Date" Value="Invoice Date" />
<asp:ListItem Text="Date Entered" Value="Date Entered" />
<asp:ListItem Text="Serial Number" Value="Serial Number" />
<asp:ListItem Text="Purchase Cost" Value="Purchase Cost" />
<asp:ListItem Text="Active" Value="Active" />
</asp:DropDownList>
<asp:DropDownList ID="ddlValue" runat="server" CssClass="textGrey10"
/>
<asp:Button ID="btnApplyFilter" runat="server" CssClass="textGrey10"
Text="Apply Filter" OnClick="btnApplyFilter_Click" />
</td>
</tr>
</table>

<table border="0" cellpadding="0" cellspacing="0" width="100%">
<tr>
<td align="left" colspan="2">
<asp:Label ID="Label1" runat="server" Text="Current Filters Applied"
CssClass="textGrey10" />
</td>
</tr>
<tr>
<td align="left" width="50%">
<asp:PlaceHolder ID="phAttribute" runat="server" />
</td>
<td align="left" width="50%">
<asp:PlaceHolder ID="phValue" runat="server" />
</td>
</tr>
</table>

Aug 20 '06 #1
5 4372
This looks like a scenario where the viewstate is not being retained
for the Placeholder or that something is happening in Page_Load which
is not being checked for this.IsPostBack

Sarat

studio60podc...@gmail.com wrote:
I have an ASP:Placeholder and I'm trying to populate with Label
controls from the code behind after a button click, essentially
creating a list of selections. But each time I click the button, it's
replacing the label in the placeholder rather than appending to it.

Is this the way the Placeholder control is supposed to work or is there
a way around this?

protected void btnApplyFilter_Click(object sender, EventArgs e)
{
Label lblAttribute = new Label();
lblAttribute.Text = ddlAttribute.SelectedItem.ToString() + ":";
lblAttribute.CssClass = "textGrey10";
phAttribute.Controls.Add(lblAttribute);

Label lblValue = new Label();
lblValue.Text = ddlValue.SelectedItem.ToString();
lblValue.CssClass = "textGrey10";
phValue.Controls.Add(lblValue);
}

<table border="0" cellpadding="0" cellspacing="0" width="100%">
<tr>
<td align="left">
<asp:Label ID="lblFilterHeader" runat="server" Text="Please select a
report filter" CssClass="textGrey10" />
</td>
</tr>
<tr>
<td align="left">
<asp:DropDownList ID="ddlAttribute" runat="server"
CssClass="textGrey10"
OnSelectedIndexChanged="ddlAttribute_SelectedIndex Changed"
AutoPostBack="true">
<asp:ListItem Text="" Value="" />
<asp:ListItem Text="Model" Value="Model" />
<asp:ListItem Text="Name" Value="Name" />
<asp:ListItem Text="Item Type" Value="Item Type" />
<asp:ListItem Text="Vendor" Value="Vendor" />
<asp:ListItem Text="Location" Value="Location" />
<asp:ListItem Text="Department" Value="Department" />
<asp:ListItem Text="Description" Value="Description" />
<asp:ListItem Text="Work Authorization" Value="Work Authorization"
/>
<asp:ListItem Text="PO Date" Value="PO Date" />
<asp:ListItem Text="Warranty Expires" Value="Warranty Expires" />
<asp:ListItem Text="Invoice Number" Value="Invoice Number" />
<asp:ListItem Text="Invoice Date" Value="Invoice Date" />
<asp:ListItem Text="Date Entered" Value="Date Entered" />
<asp:ListItem Text="Serial Number" Value="Serial Number" />
<asp:ListItem Text="Purchase Cost" Value="Purchase Cost" />
<asp:ListItem Text="Active" Value="Active" />
</asp:DropDownList>
<asp:DropDownList ID="ddlValue" runat="server" CssClass="textGrey10"
/>
<asp:Button ID="btnApplyFilter" runat="server" CssClass="textGrey10"
Text="Apply Filter" OnClick="btnApplyFilter_Click" />
</td>
</tr>
</table>

<table border="0" cellpadding="0" cellspacing="0" width="100%">
<tr>
<td align="left" colspan="2">
<asp:Label ID="Label1" runat="server" Text="Current Filters Applied"
CssClass="textGrey10" />
</td>
</tr>
<tr>
<td align="left" width="50%">
<asp:PlaceHolder ID="phAttribute" runat="server" />
</td>
<td align="left" width="50%">
<asp:PlaceHolder ID="phValue" runat="server" />
</td>
</tr>
</table>
Aug 20 '06 #2
Can you make any suggestions on how to circumvent this problem?

Aug 20 '06 #3
Yes the problem is viewstate:

"Problem:
ASP.NET gives a developer the opportunity to programmatically add controls
to a web form using ParentControl.Controls.Add(new Control());
However, these controls are not persisted in any way thus having to be
recreated for each subsequent request. "

"I have created a custom control called DynamicControlsPlaceholder that
derives from Placeholder and overrides Load- and SaveViewState.
In SaveViewState, the control hierarchy is recursively traversed and the
control type and ID persisted to a string
In LoadViewState the persisted information is used to recreate the control
tree to the state before."
http://www.denisbauer.com/ASPNETCont...aceholder.aspx

Let us know if this works for you?

Ken
Microsoft MVP [ASP.NET]
<st*************@gmail.comwrote in message
news:11**********************@h48g2000cwc.googlegr oups.com...
>I have an ASP:Placeholder and I'm trying to populate with Label
controls from the code behind after a button click, essentially
creating a list of selections. But each time I click the button, it's
replacing the label in the placeholder rather than appending to it.

Is this the way the Placeholder control is supposed to work or is there
a way around this?

protected void btnApplyFilter_Click(object sender, EventArgs e)
{
Label lblAttribute = new Label();
lblAttribute.Text = ddlAttribute.SelectedItem.ToString() + ":";
lblAttribute.CssClass = "textGrey10";
phAttribute.Controls.Add(lblAttribute);

Label lblValue = new Label();
lblValue.Text = ddlValue.SelectedItem.ToString();
lblValue.CssClass = "textGrey10";
phValue.Controls.Add(lblValue);
}

<table border="0" cellpadding="0" cellspacing="0" width="100%">
<tr>
<td align="left">
<asp:Label ID="lblFilterHeader" runat="server" Text="Please select a
report filter" CssClass="textGrey10" />
</td>
</tr>
<tr>
<td align="left">
<asp:DropDownList ID="ddlAttribute" runat="server"
CssClass="textGrey10"
OnSelectedIndexChanged="ddlAttribute_SelectedIndex Changed"
AutoPostBack="true">
<asp:ListItem Text="" Value="" />
<asp:ListItem Text="Model" Value="Model" />
<asp:ListItem Text="Name" Value="Name" />
<asp:ListItem Text="Item Type" Value="Item Type" />
<asp:ListItem Text="Vendor" Value="Vendor" />
<asp:ListItem Text="Location" Value="Location" />
<asp:ListItem Text="Department" Value="Department" />
<asp:ListItem Text="Description" Value="Description" />
<asp:ListItem Text="Work Authorization" Value="Work Authorization"
/>
<asp:ListItem Text="PO Date" Value="PO Date" />
<asp:ListItem Text="Warranty Expires" Value="Warranty Expires" />
<asp:ListItem Text="Invoice Number" Value="Invoice Number" />
<asp:ListItem Text="Invoice Date" Value="Invoice Date" />
<asp:ListItem Text="Date Entered" Value="Date Entered" />
<asp:ListItem Text="Serial Number" Value="Serial Number" />
<asp:ListItem Text="Purchase Cost" Value="Purchase Cost" />
<asp:ListItem Text="Active" Value="Active" />
</asp:DropDownList>
<asp:DropDownList ID="ddlValue" runat="server" CssClass="textGrey10"
/>
<asp:Button ID="btnApplyFilter" runat="server" CssClass="textGrey10"
Text="Apply Filter" OnClick="btnApplyFilter_Click" />
</td>
</tr>
</table>

<table border="0" cellpadding="0" cellspacing="0" width="100%">
<tr>
<td align="left" colspan="2">
<asp:Label ID="Label1" runat="server" Text="Current Filters Applied"
CssClass="textGrey10" />
</td>
</tr>
<tr>
<td align="left" width="50%">
<asp:PlaceHolder ID="phAttribute" runat="server" />
</td>
<td align="left" width="50%">
<asp:PlaceHolder ID="phValue" runat="server" />
</td>
</tr>
</table>

Aug 20 '06 #4
Yes the problem is viewstate:

"Problem:
ASP.NET gives a developer the opportunity to programmatically add controls
to a web form using ParentControl.Controls.Add(new Control());
However, these controls are not persisted in any way thus having to be
recreated for each subsequent request. "

"I have created a custom control called DynamicControlsPlaceholder that
derives from Placeholder and overrides Load- and SaveViewState.
In SaveViewState, the control hierarchy is recursively traversed and the
control type and ID persisted to a string
In LoadViewState the persisted information is used to recreate the control
tree to the state before."
http://www.denisbauer.com/ASPNETCont...aceholder.aspx

Let us know if this works for you?

Ken
Microsoft MVP [ASP.NET]
<st*************@gmail.comwrote in message
news:11**********************@74g2000cwt.googlegro ups.com...
Can you make any suggestions on how to circumvent this problem?

Aug 20 '06 #5
I decided to go a different route for the solution, but thank you for
the suggestion.

Ken Cox [Microsoft MVP] wrote:
Yes the problem is viewstate:

"Problem:
ASP.NET gives a developer the opportunity to programmatically add controls
to a web form using ParentControl.Controls.Add(new Control());
However, these controls are not persisted in any way thus having to be
recreated for each subsequent request. "

"I have created a custom control called DynamicControlsPlaceholder that
derives from Placeholder and overrides Load- and SaveViewState.
In SaveViewState, the control hierarchy is recursively traversed and the
control type and ID persisted to a string
In LoadViewState the persisted information is used to recreate the control
tree to the state before."
http://www.denisbauer.com/ASPNETCont...aceholder.aspx

Let us know if this works for you?

Ken
Microsoft MVP [ASP.NET]
<st*************@gmail.comwrote in message
news:11**********************@74g2000cwt.googlegro ups.com...
Can you make any suggestions on how to circumvent this problem?
Aug 21 '06 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: patrick_a | last post by:
Hello, I am trying to insert multiple instances of a custom user control into a placeholder on an aspx page, based on the records retrieved from the database. I use the datareader to loop through...
2
by: Mike Speak | last post by:
I have a user control that I want to use to render 4 menu items (retrieved from db) on the top of each of my asp.net pages. The user control defines a table, with one TR and one TD. Within the...
1
by: Dan | last post by:
I have an asp.net page default.aspx with a user control and a placeholder control. <html> <body> <form id="myform" method="post" runat="server" /> <PageHeader:Header id="header1"...
0
by: shark | last post by:
I have a placeholder in a control that is in turn, used as a control in a placeholder in a form. I am getting a viewstate error so I believe I have to clear my placeholder before I load the...
1
by: Angel | last post by:
I have added controls to the placeholder control. All the controls that were added have EnableViewState = true including the placeholder. One of the controls has a button that performs a postback. My...
2
by: Ben de Vette | last post by:
Hi, I like to load a UserControl onto a placeholder with some more control then just doing protected System.Web.UI.WebControls.PlaceHolder placeHolder; UserControl ascx =...
2
by: Don Wash | last post by:
Hi There! I'm creating my website with ASP.NET + XHTML, which means I will strictly adhere the XHTML standards for my web page output. I use Panel or PlaceHolder WebControls to place...
6
by: David Colliver | last post by:
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...
7
by: Brad Baker | last post by:
I am trying to programmatically set a placeholder control in csharp which is nested inside a repeater control between <ItemTemplateand </ItemTemplate> tags, however I am running into problems. I've...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.