Welcome to Professional ASP.NET - Chris Love's Official Blog Sign in | Join | Help

Chris Love's Official ASP.NET Blog

Chris Love's Helpful tips, tricks and pragmatic development knowledge for the ASP.NET world.
Add to Technorati Favorites


ASP Insider Follow Me On Twitter
MultiView where have you been?

As I play with the new controls and features in ASP.NET 2.0 I will update you.  A few weeks ago I figured out the MutliView could revolutionize my whole development structure.  If you have not found MutliView yet, go check it out.

In the past I generally developed two types of pages, a list and a detail.  Since the administrative area of the site is typically where these would reside in higher quantities, That is what evolved pretty early.  So that is two pages to keep track of an maintain, two pages to upload, etc.

Multiview has started to change this for me.  Now I can create one page and add two views, the item list and the detail/edit.  I know there are lots of examples of providing the edit view right on the same page at the same time with the list of items.  But think about this from our non-technical users, that is just plaini confusing to them.  So two pages, it is just easier for them, and they matter more than you.

Now let's get to some code.  MultiView is pretty easy to learn.  Basically you drop the control on your page, go to the HTML View (I have not found a way to do this at design time and I do not know why) and add your views.  You can have as many views as you want, so go ahead add them!  It might look something like this:

    <asp:MultiView ID="MultiView1" runat="server">
        <asp:View runat="server" ID="vList">
        </asp:View>
        <asp:View runat="server" ID="vEdit">
        </asp:View>
    </asp:MultiView>

Pretty easy.  Now you can go to design view and drop your code like you normally would.  You can even stay in HTML mode, I do a lot work this way.

But back to code here are some fundamentals you will need to know.  You need to manage your CurrentViewIndex to control which view is displayed.  This is an example in the Page_Load method.

    Protected Sub Page_Load1(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load

        If Not IsPostBack Then
           MultiView1.ActiveViewIndex = 0
           BindData()
        End If

    End Sub

If you need to change the view, typically due to an action like clicking a button it might look like this.

    Protected Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click
        MultiView1.ActiveViewIndex = 1
        ItemId = -1
        ClearDetails()
    End Sub

Let me do a little background explaining here.  ItemId is just a generic (not to be confused with generics, more like Penn State colors) Property I have defined in the page to track what Item in the list we are using at the time.  This method is to create a new item, so I set it to -1.

Next I clear the input controls used to define an item.  So this will set all the textboxes to "" or empty, clear any selections from DropDowns, CheckBoxLists, etc.  Otherwise it may have some residual from a previous item edit.

Switching back is just as simple, this is the Cancel Button Method for this page.

Protected Sub lbCancel_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles lbCancel.Click

      MultiView1.ActiveViewIndex = 0

      BindData()

End Sub

All is good.  This control is great and is the foundation for at least two more specific controls, Wizard and LoginView.  I will cover more on the MultiView and these controls in the next week or so.

 

Posted: Friday, January 06, 2006 11:21 AM

by Chris Love
Filed under: , ,

Comments

No Comments

Leave a Comment

(required) 

(required) 

(optional)

(required) 

Comment Notification

If you would like to receive an email when updates are made to this post, please register here

Subscribe to this post's comments using RSS