The user Article Management Interface in. Text is the main interface for using Advanced Panel. Compared with a common WebPanel, the Advanced Panel provides a Header column, and the [Collapsing] function can be folded without any code. This is the most distinctive feature of this control.
Controls common attributes
1. Collapsible attributes
This attribute is bool type. If it is true, a collapse button is displayed on the right side of the control to show or hide the content contained in the Panel. Otherwise, the button is not displayed, and the control becomes a non-foldable panel.
2. Collapsed attributes
This attribute is bool type. The default value is false. during initialization, all content in the panel container is displayed. If it is true, the content in the panel container is not displayed during initialization. If it is true, the result is as follows:
[Figure 1]
In the figure, only the Panel Header is displayed, but the specific content of the Panel is not displayed. You can only click the fold switch button on the right to view the details.
3. LinkBeforeHeader attributes
This attribute is of the bool type. The default value is false. If it is false, the collapse button on the right is displayed at the bottom right of the Header. Effect 2
[Figure 2]
If the value is true, the collapse button is displayed as shown in Figure 1.
4. HeaderText attributes
This attribute is string type and is used to set the content of the Header title. in example 2, the value of HeaderText is Edit Post.
5. LinkImageCollapsed attributes
This attribute is string type and is used to set the path of the image in the collapsed State of the fold button.
6. LinkImage attributes
This attribute is string type and is used to set the path of the image in the "Expand" Status of the collapse button.
7. BodyCssClass attributes
This attribute is string type, used to set the style of the content display area. Note: because the content display area is actually a div layer, the set style must conform to the <div> attribute and do not contain attributes that cannot be set .. In Text, BodyCssClass = "Edit" is set as follows:
Div. Edit {}{
Color: #333333;
Border-bottom: 1px solid # AAAAAA;
Margin-bottom: 8px;
Padding: 4px 12px;
Background: # f5f5f5;
}
Of course, you can also set some other attributes, such as border-top [upper border], border-left [left border], and border-right [right border.
8. DisplayHeader attributes
This attribute is of the bool type and is used to set whether to display the Header column.
9. HeaderCssClass attributes
This attribute is string type, used to set the Header style .. In Text, HeaderCssClass = "CollapsibleTitle" is set as follows:
Div. CollapsibleTitle {}{
Font-size: 105%;
Background: # E5E5E5;
Border-top: 1px solid # AAAAAA;
Border-bottom: 1px dashed # AAAAAA;
Font-weight: bold;
Color: #333333;
Width: auto;
Padding: 2px 12px;
Margin: 12px 0px 0px 0px;
Clear: left;
}
Here we can see border-top: solid, that is, the upper border is the solid line, border-bottom: dashed, that is, the bottom border is the dotted line.
Control Technical Analysis
1. Panel Principle
Panel itself is actually a div layer, whether it is a WebPanel built in VS or an Advanced Panel.
2. Folding effect implementation
The folding button is the key. We can see this code in the final html code:
<A id = "Edit_Link" onclick = "ToggleVisible ('edit _ CONTENTS', 'edit _ linkimag', 'image/toggle_gray_up.gif ', 'image/toggle_gray_down.gif'); return false; "href =" # ">
</A>
The onclick In the hyperlink label is overloaded. Once the button is pressed, The ToggleVisible () function is called. Let's take a look at the implementation of the ToggleVisible function:
Function ToggleVisible (targetID, imageID, linkImage, linkImageCollapsed)
{
If (document. getElementById ){
Target = document. getElementById (targetID );
If (target. style. display = "none "){
Target. style. display = "";
} Else {
Target. style. display = "none ";
}
If (linkImageCollapsed! = ""){
Image = document. getElementById (imageID );
If (target. style. display = "none "){
Image. src = linkImageCollapsed;
} Else {
Image. src = linkImage;
}
}
}
}
The parameter targetID specifies the id of the content display area, that is, the id of the div layer, and Edit_Contents in. Text. The imageID parameter specifies the image id of the displayed hide button.
This function uses getElementById in javascript to obtain the pointer of a specific html element and control the corresponding html element. As for the display and hide content, you can modify the style of the html element. the display attribute is implemented when style. display = "none", it is not displayed, if style. display =.
In fact, in this control, ToggleVisible is dynamically loaded, and this function is placed in uicontrols. in js files, you can load javascript dynamically by reloading the OnPreRender event of the Panel control. For details, see ASP.. NET Server Control and component development. The Load Code is as follows:
Protected override void OnPreRender (EventArgs e)
{
If (Collapsible ){
Page. RegisterClientScriptBlock (CLIENT_SCRIPT_KEY,
Utilities. GetClientScriptInclude (CLIENT_SCRIPT_FILE ));
}
Base. OnPreRender (e );
}
CLIENT_SCRIPT_KEY and CLIENT_SCRIPT_FILE are constants defined in the control.
3. Implementation of the Collapsed attribute
If the Collapsed attribute is true, the content area is not displayed at the beginning. This is implemented by reloading the Render method of the Panel control. The Code is as follows:
If (Collapsed)
{
_ Contents. Style. Add ("display", "none ");
_ Image. ImageUrl = LinkImageCollapsed;
}
The _ contents. Style. Add () adds style. display = "none" to the content display layer, so that the content area can be hidden during initialization.