The below code will always set the view to View1.
if (!Page.IsPostBack)
{
MultiView1.SetActiveView(View1);
}
If you want to set the ActiveView
to a specific view after the redirect then you have set your view information somewhere. like Session
or QueryString
Query string code will be like:
protected void btnSubmitAd_Click(object sender, EventArgs e)
{
if (Page.IsValid)
{
Ads ad = new Ads
{
Title = txtAdTitle.Text,
Dec = txtAdText.Text,
Name = txtName.Text,
Email = txtEmail.Text
};
context.Ads.Add(ad);
context.SaveChanges();
//MultiView1.SetActiveView(View2); No need for that as it will be lost after redirect...
//Append your ActiveView information in query string with Request.Url.AbsoluteUri
Response.Redirect(Request.Url.AbsoluteUri + "?activeView=View2");//
}
}
And on PageLoad
protected void Page_Load(object sender, EventArgs e)
{
if (!Page.IsPostBack)
{
string activeView = Request.QueryString["activeView"]
if(!string.IsNullOrEmpty(activeView) && activeView == "View2")
MultiView1.SetActiveView(View2);
else
MultiView1.SetActiveView(View1);
}
}