Posted in General

The Unnoticed .NET 2.0 Standard controls

We have noticed many new controls in .NET framework 2.0, like DataSources and GridView, DetailsView, Tree, ObjectDataSource, SiteMap, Web parts and so on. I found some controls have gone unnoticed.

MultiView and View

MultiView control composites multiple views, developer can set the ActiveViewIndex when required. This has got it purpose, as there are several instances where we have multiple views, but we have to show a view to a user based on User’s access and views are very different to each other. We typically used to achive this using Panel controls and setting their visibility property to true/false. A typical multiView control can look like…

<asp:multiview id="MultiView1" runat="server" activeviewindex="0">
    <asp:view id="View1" runat="server">
        Now showing View #1<br />
        <asp:textbox id="TextBox1" runat="server"></asp:TextBox><strong> </strong>
        <asp:button id="Button1" runat="server" text="Button"></asp:View>
    <asp:view id="View2" runat="server">
        Now showing View #2<br />
        <asp:hyperlink id="HyperLink1" runat="server" navigateurl="http://www.asp.net">HyperLink</asp:HyperLink>
        <asp:hyperlink id="HyperLink2" runat="server" navigateurl="http://www.asp.net">HyperLink</asp:HyperLink></asp:View>
    <asp:view id="View3" runat="server">
        Now showing View #3<br />
        <asp:calendar id="Calendar1" runat="server"></asp:Calendar>
    </asp:View>
</asp:MultiView>

We can set the active view by the following

MultiView1.ActiveViewIndex = DropDownList1.SelectedValue

Substitution

Substitution is useful when you have a Page/UserControl that is cached, but you want somethings to be dynamic. Substitution enables us to do this. In past we choose not to cache as one of the option. or to split the Page/UserControl intto multiple UserControls. In the below example the cached time will change every 60 seconds, but Substitution time changes for every request.


<%@ Page Language="C#" %>
<%@ OutputCache Duration="60" VaryByParam="none" %>

<script runat="server">
static string GetCurrentDate(HttpContext context)
{ return DateTime.Now.ToString(); }
</script>

<form id="form1" runat="server">
Cached Time:<%= DateTime.Now.ToString() %>
Substitution time: <asp:Substitution ID="Substitution1" runat="server" MethodName="GetCurrentDate" />
</form>

Its is intesting to note that these methods take HttpContext as argument, which is reasonable, as that’s required in most cases. We can also use Response.WriteSubstitution (new HttpResponseSubstitutionCallback(GetCurrentDate)) method to do the same too. It looks like we can get most of the string stuff. I have to explore if we can use Substitution for DataGrid or so on.

Wizard

Wizard is an other Standard control, it delivers forms in Wizard style. I will try not to use this, as when you say Wizard, it means you have a big form, which implies that users are not going to visit the site, as you might expect. Forms should be as simple as possible (KIS = keep it simple). There is lot said about Wizard at http://beta.asp.net/QUICKSTART/aspnet/doc/ctrlref/standard/wizard.aspx

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s