Wednesday, 4 April 2012

Using Multiview control in asp.net

To use Multiview control in asp.net first create an aspx page which looks something like this:


I have used three view inside a multiview control, one for personal information of a person, second for address, and third to upload the picture and submit.

Code for cs file:
protected void Page_Load(object sender, EventArgs e)
{
    //set the active view on page load
    MultiView1.SetActiveView(View1);
}
protected void Button1Continue_Click(object sender, EventArgs e)
{
    //when user click continue on view 1 set view 2 as active view
    MultiView1.SetActiveView(View2);  
}
protected void Button1Back_Click(object sender, EventArgs e)
{
    //when user clicks back button on view 2 set view 1 as active view
    MultiView1.SetActiveView(View1);
}
protected void Button2Continue_Click(object sender, EventArgs e)
{
    //when user click continue on view 2 set view 2 as active view
    MultiView1.SetActiveView(View3);
}
protected void Button2Back_Click(object sender, EventArgs e)
{
    //when user clicks back button on view 3 set view 2 as active view
    MultiView1.SetActiveView(View2);
}
protected void Button3Continue_Click(object sender, EventArgs e)
{
    //on submit button click the image uploaded by the user is saved into the Images folder in the project
    if (FileUpload1.HasFile)
        FileUpload1.SaveAs(MapPath("~/Images/" + FileUpload1.FileName));
}

When you run this, on startup only the first view that is regarding personal information will be displayed and when you fill the information and click continue second view is displayed and so on....

No comments:

Post a Comment