Ipostbackdatahandler maintains the status of the collapablepanel Control

Source: Internet
Author: User
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 !!

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.