PC Review


Reply
Thread Tools Rate Thread

ASP PlaceHolder control

 
 
studio60podcast@gmail.com
Guest
Posts: n/a
 
      20th Aug 2006
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">
<aspropDownList ID="ddlAttribute" runat="server"
CssClass="textGrey10"
OnSelectedIndexChanged="ddlAttribute_SelectedIndexChanged"
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" />
</aspropDownList>
<aspropDownList 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>

 
Reply With Quote
 
 
 
 
Sarat Pediredla
Guest
Posts: n/a
 
      20th Aug 2006
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">
> <aspropDownList ID="ddlAttribute" runat="server"
> CssClass="textGrey10"
> OnSelectedIndexChanged="ddlAttribute_SelectedIndexChanged"
> 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" />
> </aspropDownList>
> <aspropDownList 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>


 
Reply With Quote
 
studio60podcast@gmail.com
Guest
Posts: n/a
 
      20th Aug 2006
Can you make any suggestions on how to circumvent this problem?

 
Reply With Quote
 
Ken Cox [Microsoft MVP]
Guest
Posts: n/a
 
      21st Aug 2006
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]


<(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
>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">
> <aspropDownList ID="ddlAttribute" runat="server"
> CssClass="textGrey10"
> OnSelectedIndexChanged="ddlAttribute_SelectedIndexChanged"
> 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" />
> </aspropDownList>
> <aspropDownList 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>
>



 
Reply With Quote
 
Ken Cox [Microsoft MVP]
Guest
Posts: n/a
 
      21st Aug 2006
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]


<(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> Can you make any suggestions on how to circumvent this problem?
>



 
Reply With Quote
 
studio60podcast@gmail.com
Guest
Posts: n/a
 
      21st Aug 2006
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]
>
>
> <(E-Mail Removed)> wrote in message
> news:(E-Mail Removed)...
> > Can you make any suggestions on how to circumvent this problem?
> >


 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

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
Placeholder Control Bert Microsoft VB .NET 3 13th Dec 2006 07:30 AM
Placeholder control tma Microsoft ASP .NET 3 4th Aug 2004 01:40 AM
Add control to a placeholder Carlos Cruz Microsoft ASP .NET 1 12th Apr 2004 12:07 AM
Placeholder control =?Utf-8?B?Q2hhcmxpZSBEaXNvbg==?= Microsoft ASP .NET 2 24th Feb 2004 01:11 PM
bug in the placeholder control ? Maruthi Microsoft ASP .NET 1 22nd Jan 2004 03:44 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 06:39 PM.