Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > ASP .Net Web Controls > Web Custom Control Render Problem

Reply
Thread Tools

Web Custom Control Render Problem

 
 
Billy Boy
Guest
Posts: n/a
 
      03-02-2004
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);
}
}
}
 
Reply With Quote
 
 
 
 
Alvin Bruney [MVP]
Guest
Posts: n/a
 
      03-04-2004
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" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed) om...
> 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);
> }
> }
> }



 
Reply With Quote
 
 
 
 
Alvin Bruney [MVP]
Guest
Posts: n/a
 
      03-04-2004
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" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed) om...
> 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);
> }
> }
> }



 
Reply With Quote
 
Billy Boy
Guest
Posts: n/a
 
      03-04-2004
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
 
Reply With Quote
 
Alvin Bruney [MVP]
Guest
Posts: n/a
 
      03-05-2004
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" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed) om...
> 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



 
Reply With Quote
 
Billy Boy
Guest
Posts: n/a
 
      03-05-2004
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);
}
}
}
 
Reply With Quote
 
Alvin Bruney [MVP]
Guest
Posts: n/a
 
      03-05-2004
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" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed) 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);
> }
> }
> }



 
Reply With Quote
 
Billy Boy
Guest
Posts: n/a
 
      03-06-2004
Thanks Alvin I'll try that ...

Once again thanks for your time.

Billy
 
Reply With Quote
 
 
 
Reply

Thread Tools

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
Render web custom control Peter Kirk ASP .Net Web Controls 1 12-02-2006 08:20 PM
Best way to render a custom web control DalePres ASP .Net Web Controls 2 06-26-2004 01:22 PM
Page.Render do not render complete page Lau Lei Cheong ASP .Net 1 05-15-2004 04:10 AM
Using Table control in a custom composite control. Control does not render properly in design time. jb_in_marietta@yahoo.com ASP .Net Building Controls 1 07-02-2003 08:05 AM
Using Table control in a custom composite control. Control does not render properly in design time. jb_in_marietta@yahoo.com ASP .Net 0 07-01-2003 09:26 PM



Advertisments