[Import] ASP. NET 2.0 CSS friendly control adapters 1.0 is officially released

Source: Internet
Author: User

Select ASP. NET developers have been very depressed, because they chose ASP. net is to select its existing powerful web control library, and then select the powerful functions of these controls while also bringing some problems, such as some of the current complex controls, the HTML output does not conform to the current web standards, such as the gridview, Treeview, and user controls. The HTML output by these controls is a traditional table method, unlike the CSS and content Div separation methods proposed by web standards!

ASP. net Development Team is aware of this problem, with the help of ASP. the net 2.0 Framework has powerful configurable and customizable capabilities, providing a perfect solution to the problem-use. the bloadapter file configures a custom adapter for the controls on the page to replace the original non-standard solution. The set of custom adapters is ASP. NET 2.0 CSS friendly control adapters. After several beta versions were released, ASP. NET 2.0 CSS friendly control adapters version 1.0 was officially released.

The following controls do not comply with web standards in ASP. NET 2.0. Each control provides an alternative implementation that complies with web standards in ASP. NET 2.0 CSS friendly control adapters.

    1. Menu
    2. Treeview
    3. Detailsview
    4. Formview
    5. Gridview
    6. Datalist
    7. Login
    8. Changepassword
    9. Passwordrecovery
    10. Createuserwizard
    11. Loginstatus

In the app_browsers folder, you can see the cssfriendlyadapters. Browser file. Let's see how it is configured.

<Browsers>
<Browser refID = "default">
<Controladapters>
<Adapter controltype = "system. Web. UI. webcontrols. Menu"
Adaptertype = "cssfriendly. menuadapter"/>
<Adapter controltype = "system. Web. UI. webcontrols. Treeview"
Adaptertype = "cssfriendly. treeviewadapter"/>
<Adapter controltype = "system. Web. UI. webcontrols. detailsview"
Adaptertype = "cssfriendly. detailsviewadapter"/>
<Adapter controltype = "system. Web. UI. webcontrols. formview"
Adaptertype = "cssfriendly. formviewadapter"/>
<Adapter controltype = "system. Web. UI. webcontrols. datalist"
Adaptertype = "cssfriendly. datalistadapter"/>
<Adapter controltype = "system. Web. UI. webcontrols. gridview"
Adaptertype = "cssfriendly. gridviewadapter"/>
<Adapter controltype = "system. Web. UI. webcontrols. changepassword"
Adaptertype = "cssfriendly. changepasswordadapter"/>
<Adapter controltype = "system. Web. UI. webcontrols. login"
Adaptertype = "cssfriendly. loginadapter"/>
<Adapter controltype = "system. Web. UI. webcontrols. loginstatus"
Adaptertype = "cssfriendly. loginstatusadapter"/>
<Adapter controltype = "system. Web. UI. webcontrols. createuserwizard"
Adaptertype = "cssfriendly. createuserwizardadapter"/>
<Adapter controltype = "system. Web. UI. webcontrols. passwordrecovery"
Adaptertype = "cssfriendly. passwordrecoveryadapter"/>
</Controladapters>
</Browser>

<Browser parentid = "default">
<Identification>
<Useragent match = "^ w3c_validator"/>
</Identification>
<Capabilities>
<Capability value = "W3C validator"/>
<Capability value = "1.2" type = "parmname" text = "parmname"/>
<Capability value = "true"/>
<Capability value = "true"/>
<Capability value = "true"/>
<Capability value = "true"/>
<Capability value = "system. Web. UI. htmltextwriter"/>
<Capability value = "1.0" type = "parmname" text = "parmname"/>
</Capabilities>
</Browser>
</Browsers>
We can see that the adaptertype attribute cssfriendly. menuadapter is configured for all these Web controls, such as system. Web. UI. webcontrols. menu.

Next let's take a look at some of the content in cssfriendly. menuadapter.Code

Private void builditems (menuitemcollection items, bool isroot, htmltextwriter writer)
{
If (items. Count> 0)
{
Writer. writeline ();

Writer. writebegintag ("Ul ");
If (isroot)
{
Writer. writeattribute ("class", "ASPnet-menu ");
}
Writer. Write (htmltextwriter. tagrightchar );
Writer. indent ++;

Foreach (menuitem item in items)
{
Builditem (item, writer );
}

Writer. indent --;
Writer. writeline ();
Writer. writeendtag ("Ul ");
}
}

 

private void builditem (menuitem item, htmltextwriter writer)
{< br> menu = control as menu;
If (menu! = NULL) & (item! = NULL) & (writer! = NULL)
{< br> writer. writeline ();
writer. writebegintag ("Li");

string theclass = (item. childitems. Count> 0 )? "ASPnet-menu-withchildren": "ASPnet-menu-leaf";
string selectedstatusclass = getselectstatusclass (item);
If (! String. isnullorempty (selectedstatusclass)
{< br> theclass ++ = "" + selectedstatusclass;
}< br> writer. writeattribute ("class", theclass);

Writer. Write (htmltextwriter. tagrightchar );
Writer. indent ++;
Writer. writeline ();

If (item. depth <menu. staticdisplaylevels) & (menu. staticitemtemplate! = NULL) |
(Item. Depth> = menu. staticdisplaylevels) & (menu. dynamicitemtemplate! = NULL )))
{
Writer. writebegintag ("Div ");
Writer. writeattribute ("class", getitemclass (menu, item ));
Writer. Write (htmltextwriter. tagrightchar );
Writer. indent ++;
Writer. writeline ();

Menuitemtemplatecontainer Container = new menuitemtemplatecontainer (menu. Items. indexof (item), item );
If (item. depth <menu. staticdisplaylevels) & (menu. staticitemtemplate! = NULL ))
{
Menu. staticitemtemplate. instantiatein (container );
}
Else
{
Menu. dynamicitemtemplate. instantiatein (container );
}
Container. databind ();
Container. rendercontrol (writer );

Writer. indent --;
Writer. writeline ();
Writer. writeendtag ("Div ");
}
Else
{
If (islink (item ))
{
Writer. writebegintag ("");
If (! String. isnullorempty (item. navigateurl ))
{
Writer. writeattribute ("href", page. server. htmlencode (menu. resolveclienturl (item. navigateurl )));
}
Else
{
Writer. writeattribute ("href", page. clientscript. getpostbackclienthyperlink (menu, "B" + item. valuepath. replace (menu. pathseparator. tostring (), "\"), true ));
}

Writer. writeattribute ("class", getitemclass (menu, item ));
Webcontroladapterextender. writetargetattribute (writer, item. Target );

If (! String. isnullorempty (item. tooltip ))
{
Writer. writeattribute ("title", item. tooltip );
}
Else if (! String. isnullorempty (menu. tooltip ))
{
Writer. writeattribute ("title", menu. tooltip );
}
Writer. Write (htmltextwriter. tagrightchar );
Writer. indent ++;
Writer. writeline ();
}
Else
{
Writer. writebegintag ("span ");
Writer. writeattribute ("class", getitemclass (menu, item ));
Writer. Write (htmltextwriter. tagrightchar );
Writer. indent ++;
Writer. writeline ();
}

If (! String. isnullorempty (item. imageurl ))
{
Writer. writebegintag ("IMG ");
Writer. writeattribute ("src", menu. resolveclienturl (item. imageurl ));
Writer. writeattribute ("Alt ",! String. isnullorempty (item. tooltip )? Item. tooltip :(! String. isnullorempty (menu. tooltip )? Menu. tooltip: item. Text ));
Writer. Write (htmltextwriter. selfclosingtagend );
}

Writer. Write (item. Text );

If (islink (item ))
{
Writer. indent --;
Writer. writeendtag ("");
}
Else
{
Writer. indent --;
Writer. writeendtag ("span ");
}

}

If (item. childitems! = NULL) & (item. childitems. count> 0)
{< br> builditems (item. childitems, false, writer);
}

Writer. indent --;
Writer. writeline ();
Writer. writeendtag ("Li ");
}
}
As you can see, use the configuration file. browser to configure the system. Web. UI. webcontrols. adapters used by each control, and use these custom adapters to change the HTML output of the control!

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.