During the design of the collapablepanel control, a problem occurs: When a panel is expanded, the status of the Panel in the control is restored to the original status after the page is executed, is this especially depressing.
I checked msdn and learned that ipostbackdatahandler can be implemented.
The implementation is given below Code :
1. register the control in page_init as the control for sending back. Protected Override Void Oninit (eventargs E)
{
Base . Oninit (E );
// Columns the status of each coolpanel.
Foreach (Collpanel P In M_panels)
{
P. I _expanded=M_expandsolepanel? False: P. expanded;
}
If (M_expandsolepanel)
{
M_panels [0]. I _expanded= True;
}
// Register controls
If (Page ! = Null )
{
Page. registerrequirespostback (This);
}
}
2. register an htmlinputhidden control in onprerender and write the status of the subpanel set. Protected Override Void Onprerender (eventargs E)
{
Base . Onprerender (E );
String S = "" ;
Foreach (Collpanel P In M_panels)
{
S + = (P. I _expanded.tostring () = " True " ? " 1 " : " 0 " ) + " , " ;
}
If (Page ! = Null )
{
Page. registerhiddenfield (This. Clientid+ "_ State", S );
}
}
3. Finally, obtain the status from the client through loadpostdata Public Bool Loadpostdata (string postdatakey, namevaluecollection values)
{
// Obtain the status of each panel from the client
String Value = Values [ This . Clientid + " _ State " ];
If (Value ! = Null )
{
String [] S = Value. Split ( ' , ' );
For ( Int I = 0 ; I < M_panels.count; I ++ )
{< br> m_panels [I]. I _expanded = S [I] = " 1 " ? true : false ;< BR >}
}
Return False ;
}
[End]
Oh, isn't it easy !!