Do you have an Page.IsPageBack check in your page load for your user
control?
See if that helps any.
--
Regards,
Alvin Bruney [ASP.NET MVP]
Got tidbits? Get it here...
http://tinyurl.com/3he3b
"Billy Boy" <> wrote in message
news: om...
> As requested:
>
> I have created a web page involving tables and graphics (no code
> behind) and added a PlaceHolder to a one of the cells. This page is
> now my 'template' and I create various different 'User Controls' and
> add them to the PlaceHolder at different times to create various
> different pages but with the same look and feel.
> What I want to do now is place the web page 'template' into a 'Web
> Custom Control' so it can be shared and if the template needs to
> change I can change it in one place and the changes are cascaded.
> So I have created a 'Web Custom Control' that displays the tables and
> graphics (all placed in the Render Method) as required plus there is a
> PlaceHolder that is in a certain cell that is exposed as a Public
> Property of the 'Web Custom Control'.
> What I do now is create a new blank Web Project, drag the 'Web Custom
> Control' on to the default page and then I drag a new 'User control'
> on to the page. In the code behind (Page_Load) I bind the 'User
> Control' to the exposed PlaceHolder of the 'Web Custom Control' and
> all is displayed correctly.
> Now if I have 2 buttons and 2 labels on the User Control that simply
> display the words "Button1 pressed" or "Button2 pressed" respectively
> when either of the buttons are pressed I get the following problem.
> When the first button is pressed label1 display the correct string of
> "Button1 pressed" but when I press then second button I would presume
> label2 would display the correct string of "Button2 pressed" plus
> label1 would still display the correct string of "Button1 pressed"
> (this is what I want) . this isn't the case. What happens is that
> label1 returns to it default value and label2 display the correct
> string of "Button2 pressed". The ViewState is set to true for all
> controls.
>
> Can anybody tell me why this is happening?
>
> Thanks, Regards
>
> Billy
>
> Below is similar code for the 'Web Custom Control' if that helps.
>
> namespace Wcc1
> {
> [DefaultProperty("plhX"), ToolboxData("<{0}:TestCtl
> runat=server></{0}:TestCtl>")]
> public class TestCtl : System.Web.UI.WebControls.WebControl
> {
> private PlaceHolder plh = new PlaceHolder();
> [Bindable(true), Category("Appearance"), DefaultValue(null)]
> public PlaceHolder plhX {get{return plh;} set{plh = value;}}
>
> protected override void Render(HtmlTextWriter wr)
> {
> Table tab = new Table();
> TableRow row = new TableRow();
> TableCell cell1 = new TableCell();
> TableCell cell2 = new TableCell();
> TableCell cell3 = new TableCell();
>
> cell1.Text = "Cell #1";
> cell1.BorderWidth = Unit.Pixel(5);
>
> cell2.Controls.Add(plh);
> cell2.BorderWidth = Unit.Pixel(5);
>
> cell3.Text = "Cell #3";
> cell3.BorderWidth = Unit.Pixel(5);
>
> row.Cells.Add(cell1);
> row.Cells.Add(cell2);
> row.Cells.Add(cell3);
>
> tab.Rows.Add(row);
>
> tab.RenderControl(wr);
> }
> }
> }