Web Custom Control Render Problem

Discussion in 'ASP .Net Web Controls' started by Billy Boy, Mar 2, 2004.

  1. Billy Boy

    Billy Boy Guest

    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);
    }
    }
    }
     
    Billy Boy, Mar 2, 2004
    #1
    1. Advertising

  2. Your post went unanswered. Have you resolved this issue?

    --
    Regards,
    Alvin Bruney [ASP.NET MVP]
    Got tidbits? Get it here...
    http://tinyurl.com/3he3b
    "Billy Boy" <> wrote in message
    news:...
    > 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);
    > }
    > }
    > }
     
    Alvin Bruney [MVP], Mar 4, 2004
    #2
    1. Advertising

  3. Your post went unanswered. Have you resolved this issue?

    --
    Regards,
    Alvin Bruney [ASP.NET MVP]
    Got tidbits? Get it here...
    http://tinyurl.com/3he3b
    "Billy Boy" <> wrote in message
    news:...
    > 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);
    > }
    > }
    > }
     
    Alvin Bruney [MVP], Mar 4, 2004
    #3
  4. Billy Boy

    Billy Boy Guest

    At present I have no answers ...

    Maybe it can't be done and Web Custom Controls should only contain
    Extented Controls rather than full 'Static' web pages.

    Any advice would be helpful.

    Regards

    Billy
     
    Billy Boy, Mar 4, 2004
    #4
  5. Can you post the original question. I don't have it. I can take a look if
    you do.

    --
    Regards,
    Alvin Bruney [ASP.NET MVP]
    Got tidbits? Get it here...
    http://tinyurl.com/3he3b
    "Billy Boy" <> wrote in message
    news:...
    > At present I have no answers ...
    >
    > Maybe it can't be done and Web Custom Controls should only contain
    > Extented Controls rather than full 'Static' web pages.
    >
    > Any advice would be helpful.
    >
    > Regards
    >
    > Billy
     
    Alvin Bruney [MVP], Mar 5, 2004
    #5
  6. Billy Boy

    Billy Boy Guest

    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);
    }
    }
    }
     
    Billy Boy, Mar 5, 2004
    #6
  7. 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:...
    > 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);
    > }
    > }
    > }
     
    Alvin Bruney [MVP], Mar 5, 2004
    #7
  8. Billy Boy

    Billy Boy Guest

    Thanks Alvin I'll try that ...

    Once again thanks for your time.

    Billy
     
    Billy Boy, Mar 6, 2004
    #8
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Replies:
    0
    Views:
    732
  2. Lau Lei Cheong

    Page.Render do not render complete page

    Lau Lei Cheong, May 15, 2004, in forum: ASP .Net
    Replies:
    1
    Views:
    2,092
    Lau Lei Cheong
    May 15, 2004
  3. Replies:
    1
    Views:
    394
    Teemu Keiski
    Jul 2, 2003
  4. DalePres

    Best way to render a custom web control

    DalePres, Jun 26, 2004, in forum: ASP .Net Web Controls
    Replies:
    2
    Views:
    104
    DalePres
    Jun 26, 2004
  5. Glenn Gillen
    Replies:
    0
    Views:
    288
    Glenn Gillen
    Nov 17, 2006
Loading...

Share This Page