Web Custom Control Render Problem

B

Billy Boy

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);
}
}
}
 
A

Alvin Bruney [MVP]

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 said:
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);
}
}
}
 
A

Alvin Bruney [MVP]

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 said:
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);
}
}
}
 
B

Billy Boy

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
 
A

Alvin Bruney [MVP]

Can you post the original question. I don't have it. I can take a look if
you do.
 
B

Billy Boy

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);
}
}
}
 
A

Alvin Bruney [MVP]

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 said:
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);
}
}
}
 

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

Members online

No members online now.

Forum statistics

Threads
473,764
Messages
2,569,564
Members
45,041
Latest member
RomeoFarnh

Latest Threads

Top