[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

microsoft.public.dotnet.framework.aspnet.buildingcontrols

CompositeControls and RecreateChildControls

jeljeljel

9/20/2007 5:20:00 PM

I have a CompositeControl (called SimplePager) that creates an
UpdatePanel in its CreateChildControls override. The CompositeControl
uses two LinkButtons to control the forward/backward state. W/out the
use of the UpdatePanel it works just great. However, as a learning
exercise I want to AJAXify the control. I am placing the entire
control in an UpdatePanel. During the link click event handler, I
make a call to RecreateChildControls() which throws an exception.

This is so close to working. Can someone suggest how to accomplish
what I am trying to do with an UpdatePanel?

My class is copied below.

Thanks,
John


public class SimplePager : CompositeControl
{
private int _currentRecord;
private int _totalRecords;

public SimplePager(int totalRecords)
{
_totalRecords = totalRecords;
_currentRecord = 1;
}

protected override void OnInit(EventArgs e)
{
Page.RegisterRequiresControlState(this);

EnsureChildControls();

base.OnInit(e);
}

protected override void LoadControlState(object savedState)
{
int[] state;

state = (int[])savedState;

_currentRecord = state[0];
_totalRecords = state[1];
}

protected override object SaveControlState()
{
int[] state;

state = new int[] { _currentRecord, _totalRecords };

return state;
}

protected override void CreateChildControls()
{
HtmlGenericControl div;
LinkButton linkButton;
UpdatePanel updatePanel;
Label label;

div = new HtmlGenericControl("div");
Controls.Add(div);

updatePanel = new UpdatePanel();
updatePanel.ID = this.ID + "BWPagerUpdatePanel";
updatePanel.ChildrenAsTriggers = true;
updatePanel.UpdateMode =
UpdatePanelUpdateMode.Conditional;
div.Controls.Add(updatePanel);

linkButton = new LinkButton();
linkButton.Text = "<< prev";
linkButton.ID = "prevPage";
linkButton.Click += new EventHandler(linkButton_Click);

updatePanel.ContentTemplateContainer.Controls.Add(linkButton);

linkButton = new LinkButton();
linkButton.Text = "next >>";
linkButton.ID = "nextPage";
linkButton.Click += new EventHandler(linkButton_Click);

updatePanel.ContentTemplateContainer.Controls.Add(linkButton);

label = new Label();
label.ID = "SimplePagerTextBox";
label.Text = String.Format("&nbsp;&nbsp;Page {0} of {1}",
_currentRecord, _totalRecords);
updatePanel.ContentTemplateContainer.Controls.Add(label);

base.CreateChildControls();
}

private void linkButton_Click(object sender, EventArgs e)
{
LinkButton linkButton = sender as LinkButton;

if (PageChange != null)
{
switch (linkButton.ID)
{
case "prevPage":
if (_currentRecord > 1)
_currentRecord--;
break;

case "nextPage":
if (_currentRecord < _totalRecords)
_currentRecord++;
break;
}

PageChange(this, _currentRecord);

RecreateChildControls();
}
}

public int CurrentRecord
{
get
{
return _currentRecord;
}
}

public delegate void PageChangeEvent(object sender, int
newPage);
public event PageChangeEvent PageChange;
}

7 Answers

Nathan Sokalski

9/28/2007 5:25:00 AM

0

I am not an expert with using UpdatePanels in CompositeControls, but I am
wondering if the Control rendering process is getting confused somehow
because of the fact that the Controls get added to
updatePanel.ContentTemplateContainer.Controls rather than
updatePanel.Controls? You may want to see if including the RenderContents()
method helps (I don't know if it will or not, but it's worth a try).
Something else I would like to point out, just as a suggestion, is that you
are placing all of your controls into a div tag. There is nothing wrong with
this, except that it is inefficient because the CompositeControl places all
the rendered Controls into a div by default anyway. To control what tag
everything is placed into and what attributes are added to that tag, use the
following methods (note that my code is in VB.NET, but I'm sure you can do
the necessary translation):

Protected Overrides ReadOnly Property TagKey() As
System.Web.UI.HtmlTextWriterTag
'This method returns the tag that all rendered controls will be placed
into
Get
Return HtmlTextWriterTag.Div
End Get
End Property

Protected Overrides Sub AddAttributesToRender(ByVal writer As
System.Web.UI.HtmlTextWriter)
'Use this method to add attributes to the tag returned from the TagKey
property
writer.AddAttribute(HtmlTextWriterAttribute.Align, "left")
MyBase.AddAttributesToRender(writer)
End Sub

If you view the output of your current code, you will see a div nested
inside a div, if you use TagKey and AddAttributesToRender you will only see
one. As for the UpdatePanel, I don't know if my suggestion will help, but it
is good programming practice to implement it anyway. Good Luck!
--
Nathan Sokalski
njsokalski@hotmail.com
http://www.nathansok...

"jeljeljel" <livermore.john@gmail.com> wrote in message
news:1190308789.788109.286610@w3g2000hsg.googlegroups.com...
>I have a CompositeControl (called SimplePager) that creates an
> UpdatePanel in its CreateChildControls override. The CompositeControl
> uses two LinkButtons to control the forward/backward state. W/out the
> use of the UpdatePanel it works just great. However, as a learning
> exercise I want to AJAXify the control. I am placing the entire
> control in an UpdatePanel. During the link click event handler, I
> make a call to RecreateChildControls() which throws an exception.
>
> This is so close to working. Can someone suggest how to accomplish
> what I am trying to do with an UpdatePanel?
>
> My class is copied below.
>
> Thanks,
> John
>
>
> public class SimplePager : CompositeControl
> {
> private int _currentRecord;
> private int _totalRecords;
>
> public SimplePager(int totalRecords)
> {
> _totalRecords = totalRecords;
> _currentRecord = 1;
> }
>
> protected override void OnInit(EventArgs e)
> {
> Page.RegisterRequiresControlState(this);
>
> EnsureChildControls();
>
> base.OnInit(e);
> }
>
> protected override void LoadControlState(object savedState)
> {
> int[] state;
>
> state = (int[])savedState;
>
> _currentRecord = state[0];
> _totalRecords = state[1];
> }
>
> protected override object SaveControlState()
> {
> int[] state;
>
> state = new int[] { _currentRecord, _totalRecords };
>
> return state;
> }
>
> protected override void CreateChildControls()
> {
> HtmlGenericControl div;
> LinkButton linkButton;
> UpdatePanel updatePanel;
> Label label;
>
> div = new HtmlGenericControl("div");
> Controls.Add(div);
>
> updatePanel = new UpdatePanel();
> updatePanel.ID = this.ID + "BWPagerUpdatePanel";
> updatePanel.ChildrenAsTriggers = true;
> updatePanel.UpdateMode =
> UpdatePanelUpdateMode.Conditional;
> div.Controls.Add(updatePanel);
>
> linkButton = new LinkButton();
> linkButton.Text = "<< prev";
> linkButton.ID = "prevPage";
> linkButton.Click += new EventHandler(linkButton_Click);
>
> updatePanel.ContentTemplateContainer.Controls.Add(linkButton);
>
> linkButton = new LinkButton();
> linkButton.Text = "next >>";
> linkButton.ID = "nextPage";
> linkButton.Click += new EventHandler(linkButton_Click);
>
> updatePanel.ContentTemplateContainer.Controls.Add(linkButton);
>
> label = new Label();
> label.ID = "SimplePagerTextBox";
> label.Text = String.Format("&nbsp;&nbsp;Page {0} of {1}",
> _currentRecord, _totalRecords);
> updatePanel.ContentTemplateContainer.Controls.Add(label);
>
> base.CreateChildControls();
> }
>
> private void linkButton_Click(object sender, EventArgs e)
> {
> LinkButton linkButton = sender as LinkButton;
>
> if (PageChange != null)
> {
> switch (linkButton.ID)
> {
> case "prevPage":
> if (_currentRecord > 1)
> _currentRecord--;
> break;
>
> case "nextPage":
> if (_currentRecord < _totalRecords)
> _currentRecord++;
> break;
> }
>
> PageChange(this, _currentRecord);
>
> RecreateChildControls();
> }
> }
>
> public int CurrentRecord
> {
> get
> {
> return _currentRecord;
> }
> }
>
> public delegate void PageChangeEvent(object sender, int
> newPage);
> public event PageChangeEvent PageChange;
> }
>


Mr. Joseph Littleshoes Esq.

7/3/2010 5:13:00 PM

0

Aine wrote:

> On Jul 2, 10:16 pm, JL wrote:
>
> >Lady Azure, Baroness of the North Pole wrote:
> >
> >
> >
> >
> >
> >
> >
> >
> >>JL wrote:
> >
> >>>Lady Azure, Baroness of the North Pole wrote:
> >
> >>>>JL wrote:
> >
> >>>>>Lady Azure, Baroness of the North Pole wrote:
> >
> >>>>>>Those who have read my stuff are aware of my position
> >
> >>>>>No. I Am not.
> >
> >>>>YES
> >
> >>>No.
> >
> >>YES!!!!!!!
> >>I met you way before I came over here to WICCA, you are on Natives,
> >>hunting
> >>Shaman, like Sid was doing to Wicca!!!!
> >
> >Nope, you dont have a position other than the one you habitualy assume
> >when display your ignorant arrogance for everyone to see.<
>
>
> The problem as I see it and it is really not a problem that "I" see it
> but that you don't JL is that you make little sense in some moments as
> well. Nothing worse then those who bitch about something while they
> are doing the same thing.
> You are as Mad a Hatter as I or Lady A at any given moment.

While i agreee that the craziest, sickest people are those that dont
know how crazy/sick we all are, still this "Azure" seems to me to be
capo de tutti cappi of crazyness, here, at this time.

There have been worse, more abusive or foul mouthed posters here before,
that would make Azure look blushingly innocnet by comparison but as for
just plain old nuttiness Azure takes the cake. Tops it with ice cream
and serves it on an elaborate silver platter. Engraved with her family
heraldry:)

With that she will probly end up a dainty morsel on the hors de oeuver
tray of the universe and be absient mindely consumed by some over weight
dowager in a flannel shirt and work boots:)

--

Mr. Joseph Paul Littleshoes Esq.

Domine, dirige nos.

Let the games begin!
http://fredeeky.typepad.com/fredeeky/files/sf_...

Owner|Moderator
http://groups.yahoo.com/grou...
http://groups.yahoo.com/group/SomeT...
Joe's XXX Blog http://joe93418.blo...

"...existential brain matter leads easily to the conclusion of an
epiphenomenological consciousness that can be reduced solely to the
material...."

"The probability for an event that can happen in two indestinguishable
ways is the sum of the probability of each way considered seperetly."

"Yes, at all cost wealth must stay in the hands of the few and be maximised
by moving its capital to the cheapest labour.
We all work harder and harder to achieve ever more pointless objectives,
but mark my words, the end is nigh sinners, the end is nigh! While we all
watched each other and god we forgot mother earth and our drive for more
and more is reaching the end of the line and all will end in hell and
climate change. Repent sinners! Technology must be used to reduce work not
increase it, we must learn to sit by the sweet waters of our rivers playing
our lyres, not flying to somebody else sweet waters to be photographed
grinning for Facebook."

Aine

7/3/2010 7:35:00 PM

0

On Jul 3, 10:13 am, JL <jpsti...@isp.com> wrote:
> Aine wrote:
> > On Jul 2, 10:16 pm, JL  wrote:
>
> > >Lady Azure, Baroness of the North Pole wrote:
>
> > >>JL wrote:
>
> > >>>Lady Azure, Baroness of the North Pole wrote:
>
> > >>>>JL wrote:
>
> > >>>>>Lady Azure, Baroness of the North Pole wrote:
>
> > >>>>>>Those who have read my stuff are aware of my position
>
> > >>>>>No. I Am not.
>
> > >>>>YES
>
> > >>>No.
>
> > >>YES!!!!!!!
> > >>I met you way before I came over here to WICCA, you are on Natives,
> > >>hunting
> > >>Shaman, like Sid was doing to Wicca!!!!
>
> > >Nope, you dont have a position other than the one you habitualy assume
> > >when display your ignorant arrogance for everyone to see.<
>
> > The problem as I see it and it is really not a problem that "I" see it
> > but that you don't JL is that you make little sense in some moments as
> > well. Nothing worse then those who bitch about something while they
> > are doing the same thing.
> > You are as Mad a Hatter as I or Lady A at any given moment.
>
> While i agreee that the craziest, sickest people are those that dont
> know how crazy/sick we all are, still this "Azure" seems to me to be
> capo de tutti cappi of crazyness, here, at this time.
>
> There have been worse, more abusive or foul mouthed posters here before,
> that would make Azure look blushingly innocnet by comparison but as for
> just plain old nuttiness Azure takes the cake.  Tops it with ice cream
> and serves it on an elaborate silver platter.  Engraved with her family
> heraldry:)
>
> With that she will probly end up a dainty morsel on the hors de oeuver
> tray of the universe and be absient mindely consumed by some over weight
> dowager in a flannel shirt and work boots:)

Possibly, but it will be funnier then hell if Lady A is in charge of
you in the afterlife. Totally lucid and suddenly all that was said
here makes sense to you because you went through enlightenment.
Hahaha..ya, I did go there!! ;)

Mr. Joseph Littleshoes Esq.

7/3/2010 9:57:00 PM

0

Aine wrote:

> On Jul 3, 10:13 am, JL wrote:
>
> >Aine wrote:
> >
> >>On Jul 2, 10:16 pm, JL wrote:
> >
> >>>Lady Azure, Baroness of the North Pole wrote:
> >
> >>>>JL wrote:
> >
> >>>>>Lady Azure, Baroness of the North Pole wrote:
> >
> >>>>>>JL wrote:
> >
> >>>>>>>Lady Azure, Baroness of the North Pole wrote:
> >
> >>>>>>>>Those who have read my stuff are aware of my position
> >
> >>>>>>>No. I Am not.
> >
> >>>>>>YES
> >
> >>>>>No.
> >
> >>>>YES!!!!!!!
> >>>>I met you way before I came over here to WICCA, you are on Natives,
> >>>>hunting
> >>>>Shaman, like Sid was doing to Wicca!!!!
> >
> >>>Nope, you dont have a position other than the one you habitualy assume
> >>>when display your ignorant arrogance for everyone to see.<
> >
> >>The problem as I see it and it is really not a problem that "I" see it
> >>but that you don't JL is that you make little sense in some moments as
> >>well. Nothing worse then those who bitch about something while they
> >>are doing the same thing.
> >>You are as Mad a Hatter as I or Lady A at any given moment.
> >
> >While i agreee that the craziest, sickest people are those that dont
> >know how crazy/sick we all are, still this "Azure" seems to me to be
> >capo de tutti cappi of crazyness, here, at this time.
> >
> >There have been worse, more abusive or foul mouthed posters here before,
> >that would make Azure look blushingly innocnet by comparison but as for
> >just plain old nuttiness Azure takes the cake. Tops it with ice cream
> >and serves it on an elaborate silver platter. Engraved with her family
> >heraldry:)
> >
> >With that she will probly end up a dainty morsel on the hors de oeuver
> >tray of the universe and be absient mindely consumed by some over weight
> >dowager in a flannel shirt and work boots:)
>
>
> Possibly, but it will be funnier then hell if Lady A is in charge of
> you in the afterlife. Totally lucid and suddenly all that was said
> here makes sense to you because you went through enlightenment.
> Hahaha..ya, I did go there!! ;)
>
At least theres a cohearancy to your expression of your thoughts,
sometimes i think that bare ass bi polar "Lady" is just whacking the
keyboard at random:)

And such mythic justifications! i am a bit impressed with her audacity,
but ultimaelty its undefensable audacity.

Shes like the marketing genius that took some cheap bit of nothing that
usually sell for a few dollars and made it pricey, very, very price,
but she figured out, smart girl that she is, she only had to sell one.
The P.T. Barnum school of marketing "theres a sucker born every minute."

At this point i would accept as more than plausable, and probly likely
that the only ones that have bought in to her lunacy is her local, state
and federal social service agencies.

I vaguely recall some one claiming they "fingered" her with a "whois"
trace route and got some sort of public access computer. Library or a
netcafe or something, i dont recall precisely which?

Though it does seem to me, that whilethe generalized level of craziness
on unmoderated forums is about the same, i seem to be seeing fewer out
right messiahs or saviours or one of a kind unique only and one true way
types.

Which this so called "Lady" seems to be trying to float the idea of,
that she somethow represents some sort of specifically messainic,
salvationary army of myth and legend. How quiant, charming, really,
these culturaly antique artifices, when you occasinaly get to reference
them. In real life:)

And not just as a foot note in a text one glances, fleetingly as, but
literaly, holding the broken shard in your hand and marveling at it:)

The heroic as an ideal is not to be dismissed.

But the routine mock heroics that many people engage in, as a counter
irritant at best, a placebo at worst, both here and in real life are
easily dismissed for the faux and mock and theatrical posturing they
tend to be.

And if Azure is just a role it has chosen to play, this way, well, shes
not such a great conversatinialist, at least epistelogicaly, that i
would give her credit for being an equaly a great actress, rather the
reverse, that shes as poor an actrress as she is an episoloary
conversation, that could sustain the role she tries to play here.

Of course, for the cognescenti, the out, there, is simple, Stanislawsky
method. All she has to do is be her sefl:) to play the role as her
self. Rather than any other historic or literary model, she plays
'Herself" in the great mythic drama around her.

In that role the Lady Azure projects an almost irrelevent evil.

Her sorceries are neutered by the insignificance of the role.

The strength and passion she breings to the role are outstanding but it
is all sound and fury signfying nothing, a brief foot note in the text
about an old, antique supertion regarding the work. "Break a leg" and
all that:)

--

Mr. Joseph Paul Littleshoes Esq.

Domine, dirige nos.

Let the games begin!
http://fredeeky.typepad.com/fredeeky/files/sf_...

Owner|Moderator
http://groups.yahoo.com/grou...
http://groups.yahoo.com/group/SomeT...
Joe's XXX Blog http://joe93418.blo...

"...existential brain matter leads easily to the conclusion of an
epiphenomenological consciousness that can be reduced solely to the
material...."

"The probability for an event that can happen in two indestinguishable
ways is the sum of the probability of each way considered seperetly."

"Yes, at all cost wealth must stay in the hands of the few and be maximised
by moving its capital to the cheapest labour.
We all work harder and harder to achieve ever more pointless objectives,
but mark my words, the end is nigh sinners, the end is nigh! While we all
watched each other and god we forgot mother earth and our drive for more
and more is reaching the end of the line and all will end in hell and
climate change. Repent sinners! Technology must be used to reduce work not
increase it, we must learn to sit by the sweet waters of our rivers playing
our lyres, not flying to somebody else sweet waters to be photographed
grinning for Facebook."

Lady Azure, Baroness of the North Pole

7/4/2010 2:57:00 AM

0



JL wrote:

> Aine wrote:
>
> > On Jul 2, 10:16 pm, JL wrote:
> >
> > >Lady Azure, Baroness of the North Pole wrote:
> > >
> > >
> > >
> > >
> > >
> > >
> > >
> > >
> > >>JL wrote:
> > >
> > >>>Lady Azure, Baroness of the North Pole wrote:
> > >
> > >>>>JL wrote:
> > >
> > >>>>>Lady Azure, Baroness of the North Pole wrote:
> > >
> > >>>>>>Those who have read my stuff are aware of my position
> > >
> > >>>>>No. I Am not.
> > >
> > >>>>YES
> > >
> > >>>No.
> > >
> > >>YES!!!!!!!
> > >>I met you way before I came over here to WICCA, you are on Natives,
> > >>hunting
> > >>Shaman, like Sid was doing to Wicca!!!!
> > >
> > >Nope,

YEP!!!!!!

Lady Azure, Baroness of the North Pole

7/4/2010 3:07:00 AM

0



Aine wrote:

> On Jul 3, 10:13 am, JL <jpsti...@isp.com> wrote:
> > Aine wrote:
> > > On Jul 2, 10:16 pm, JL wrote:
> >
> > > >Lady Azure, Baroness of the North Pole wrote:
> >
> > > >>JL wrote:
> >
> > > >>>Lady Azure, Baroness of the North Pole wrote:
> >
> > > >>>>JL wrote:
> >
> > > >>>>>Lady Azure, Baroness of the North Pole wrote:
> >
> > > >>>>>>Those who have read my stuff are aware of my position
> >
> > > >>>>>No. I Am not.
> >
> > > >>>>YES
> >
> > > >>>No.
> >
> > > >>YES!!!!!!!
> > > >>I met you way before I came over here to WICCA, you are on Natives,
> > > >>hunting
> > > >>Shaman, like Sid was doing to Wicca!!!!
> >
> > > >Nope, you dont have a position other than the one you habitualy assume
> > > >when display your ignorant arrogance for everyone to see.<
> >
> > > The problem as I see it and it is really not a problem that "I" see it
> > > but that you don't JL is that you make little sense in some moments as
> > > well. Nothing worse then those who bitch about something while they
> > > are doing the same thing.
> > > You are as Mad a Hatter as I or Lady A at any given moment.
> >
> > While i agreee that the craziest, sickest people are those that dont
> > know how crazy/sick we all are, still this "Azure" seems to me to be
> > capo de tutti cappi of crazyness, here, at this time.
> >
> > There have been worse, more abusive or foul mouthed posters here before,
> > that would make Azure look blushingly innocnet by comparison but as for
> > just plain old nuttiness Azure takes the cake. Tops it with ice cream
> > and serves it on an elaborate silver platter. Engraved with her family
> > heraldry:)
> >
> > With that she will probly end up a dainty morsel on the hors de oeuver
> > tray of the universe and be absient mindely consumed by some over weight
> > dowager in a flannel shirt and work boots:)
>
> Possibly, but it will be funnier then hell if Lady A is in charge of
> you in the afterlife.

Sorta Kinda, but hey, some get in the Door, some just get to use the hot tubs
on the outside!

Lady Azure, Baroness of the North Pole

7/4/2010 3:11:00 AM

0



JL wrote:
Incoherent drivel, libeling others for his amusement

> Aine wrote:
>
> > On Jul 3, 10:13 am, JL wrote:

Who cares!
Just another Brit in Feathers pretending he is a Cherokee!