神刀安全网

MultiView Control And View Control In ASP.NET

In this article you will learn about MultiView control and View control.

  1. Defination / Introduction
  2. Step by step implemation.
  3. Difference between MultiView Control vs Wizard control

Definition / Introduction

Multiview and View are both server controls. Multiview control and View control are used together. Multiview is parent control for View control. As the name defines itself, Multiview control is used to control various type of views.

Multiview contro was introduced in .Net Framework version 2.0.

Inside View control we are usin the rest of server controls. Viewis operated through MultiView1.ActiveViewIndex, and this property will display appropriate view as per the indexed numbers of view. If no view is active index will return -1 and as usual index value starts from 0.

Multiview control helps to display or render the particular view on the page.

This can be used for Survey, E-Commerce and Data entry Forms as per your requirement.

  • Prefix for MultiView control is mv
  • Prefix for View control is v

MultiView control

<asp:MultView ID= "mvEntryForm" runat= "server">      <%--[View control codes come inside of MultiView]--%>   </asp:MultiView>   

View Control

<asp:View ID= "vAddressDetail" runat= "server">   </asp:View>   

Note

View control is used inside of MultiView contro and looks like this way:

<asp:MultView ID= "mvEntryForm" runat= "server">      <asp:View ID= "vAddressDetail" runat= "server"> </asp:View>   </asp:MultiView>   

MultiView Control and Wizard Control difference between

Multiview control and wizard control are more or lessthe same but one major difference between them is the rich user interface in wizard control. Wizard control has side bar and Next, Previous and Finish buttons. A side bar is included to navigate among the various steps in the Wizard control.

For information on Multiview control visit following link .

Logic of Implementation / Implementation’s Scenario

Friend Data Entry Form

We will implement MultiView/View control on Friend Data Entry Screen where we accept following detail in different – different views. Here we have used the  following 4 (Four) views:

  • Address Detail
  • Contact Detail
  • Education Detail
  • Preview and Submit Detail

To implement a MultiView and View we had used the following things:

  1. Create a ASP.NET Empty Website project named: MultiViewAndView.
    MultiView Control And View Control In ASP.NET
  2. Add new WebForm named : Default.aspx.
    Right click on solution explorer, Select Add –> Add New Item –> Insert a New WebForm.
    MultiView Control And View Control In ASP.NET

UI Explaination

Total four views:

  • Address Detail
  • Contact Detail
  • Education Detail
  • Preview and Submit Detail

Here, you can see dropdown list where you can switch the view.

MultiView Control And View Control In ASP.NET

Address View

MultiView Control And View Control In ASP.NET

Contact Detail

MultiView Control And View Control In ASP.NET

Education Detail

MultiView Control And View Control In ASP.NET

Preview and Submit

MultiView Control And View Control In ASP.NET

Default.aspx code

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %>   <!DOCTYPE html>      <html xmlns="http://www.w3.org/1999/xhtml">   <head runat="server">       <title></title>   </head>   <body>       <form id="form1" runat="server">          <div>           <%--Extra Navigation tool for navigation.            You can directly jump to select view with help of Selection from Dropdown list.--%>              <asp:DropDownList ID="ddlDetail" runat="server" AutoPostBack="true" >               <asp:ListItem Text="1.Address Detail" Value ="0" Selected="True" ></asp:ListItem>               <asp:ListItem Text="2.Contact Detail" Value ="1"></asp:ListItem>               <asp:ListItem Text="3.Education Detail" Value ="2"></asp:ListItem>               <asp:ListItem Text="4.Preview & Submit" Value ="3"></asp:ListItem>           </asp:DropDownList>              <br />              <br />                         <table>                  <tr>                      <td>                          Name                      </td>                      <td>                          <asp:TextBox ID="txtName" runat="server"></asp:TextBox>                      </td>                  </tr>                  <tr>                      <td>                          Birth Date                      </td>                      <td>                          <asp:TextBox ID="txtBirthDate" runat="server"></asp:TextBox>                      </td>                  </tr>              </table>                 <br />              <br />              <%--MultiView control which having nos. of Views--%>           <asp:MultiView ID="mvEntryForm" runat="server">                              <%--[View control comes inside]--%>                  <asp:View ID="vAddressDetail" runat="server">                 Address  <asp:TextBox ID="txtAddress" runat="server" TextMode="MultiLine"></asp:TextBox>                   <br />                   <br />                 <asp:Button ID="btnNextContactDetail" runat="server" Text="Next" title="Next - Contact Detail" />               </asp:View>                  <asp:View ID="vContactDetail" runat="server">                    Mobile Number  <asp:TextBox ID="txtMobile" runat="server"></asp:TextBox>                   <br />                   Email ID  <asp:TextBox ID="txtEmailID" runat="server"></asp:TextBox>                 <br />                 <br />                 <asp:Button ID="btnPrevAddressDetail" runat="server" Text="Previous" title="Previous - Address Detail" />                 <asp:Button ID="btnNextEducationDetail" runat="server" Text="Next" title="Next - Education Detail" />               </asp:View>                  <asp:View ID="vEducationDetail" runat="server">                   Education Detail  <asp:TextBox ID="txtEducation" runat="server" TextMode="MultiLine"></asp:TextBox>                 <br />                 <br />                 <asp:Button ID="btnPrevContactDetail" runat="server" Text="Previous" title="Previous - Contact Detail"/>                 <asp:Button ID="btnNextPreviewAndSubmit" runat="server" Text="Next" title="Next - Preview & Submit" />               </asp:View>                  <asp:View ID="vPreviewAndSubmit" runat="server">                                       <asp:Label ID="lblSummary" runat="server" Font-Bold="true" Font-Size="Large"></asp:Label>                      <table>                       <tr>                           <td>                               <b>Address Detail</b><br />                               <asp:Label ID="lblAddressDetail" runat="server" ></asp:Label>                               <br />                               <br />                           </td>                       </tr>                       <tr>                           <td>                               <b>Contact Detail</b><br />                               <asp:Label ID="lblContactDetail" runat="server" ></asp:Label>                               <br />                               <br />                           </td>                       </tr>                       <tr>                           <td>                               <b>Education Detail</b><br />                               <asp:Label ID="lblEducationDetail" runat="server" ></asp:Label>                               <br />                               <br />                           </td>                       </tr>                   </table>                 <asp:Button ID="btnEducationDetail" runat="server" Text="Previous" title="Previous - Education Detail"/>                 <asp:Button ID="btnSubmit" runat="server" Text="Submit" title="Submit" />               </asp:View>           </asp:MultiView>          </div>       </form>   </body>   </html>   

Default.aspx.cs

using System;   using System.Collections.Generic;   using System.Linq;   using System.Web;   using System.Web.UI;   using System.Web.UI.WebControls;      public partial class _Default : System.Web.UI.Page   {          protected void Page_Load(object sender, EventArgs e)       {           mvEntryForm.ActiveViewIndex = 0;       }                protected void btnNextContactDetail_Click(object sender, EventArgs e)       {           mvEntryForm.ActiveViewIndex = 1;          }       protected void btnPrevAddressDetail_Click(object sender, EventArgs e)       {          }       protected void btnNextEducationDetail_Click(object sender, EventArgs e)       {           mvEntryForm.ActiveViewIndex = 2;       }       protected void btnPrevContactDetail_Click(object sender, EventArgs e)       {          }       protected void btnNextPreviewAndSubmit_Click(object sender, EventArgs e)       {           mvEntryForm.ActiveViewIndex = 3;           lblSummary.Text = "Hello, " + txtName.Text.ToUpper() + "<br><br> <p style=" + "/"font-size:12px/"" + ">Please, Check your detail and submit.</p>";           lblAddressDetail.Text = txtAddress.Text;           lblContactDetail.Text = "Mobile Number : " + txtMobile.Text + "<br>" + "Email ID : " + txtEmailID.Text;           lblEducationDetail.Text = txtEducation.Text;          }       protected void ddlDetail_SelectedIndexChanged(object sender, EventArgs e)       {           mvEntryForm.ActiveViewIndex = Convert.ToInt16(ddlDetail.SelectedValue);          }       protected void btnEducationDetail_Click(object sender, EventArgs e)       {           mvEntryForm.ActiveViewIndex = 2;       }   }   

转载本站任何文章请注明:转载至神刀安全网,谢谢神刀安全网 » MultiView Control And View Control In ASP.NET

分享到:更多 ()

评论 抢沙发

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址