Question

I'm trying to set a multiview control to the right view by calling a method from the code behind, which returns the value 0, but it won't return anything.

I have created a test method, which won't work:

MasterPage.aspx

<asp:MultiView ID="MultiView1" runat="server" ActiveViewIndex='<%# test() %>'>

                    <asp:View ID="LoginPnl" runat="server">
                        <a href="Login.aspx">Log ind</a>
                    </asp:View>

                    <asp:View ID="LogoutPnl" runat="server">
                        <a href="#">Min side</a>
                        <a href="#">Log ud</a>
                    </asp:View>
                </asp:MultiView>

MasterPage.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 landrupdans : System.Web.UI.MasterPage
{
    protected void Page_Load(object sender, EventArgs e)
    {
    }

    protected int test()
    {
        return 0;
    }

}

I hope someone can tell me, if it is possible at all to call methods from masterpages since it worked on another page.

Was it helpful?

Solution

One thing you need to do:

  1. DataBind the MultiView.

2. Declare the method as public.

This code worked for me:

protected void Page_Load(object sender, EventArgs e)
{
    MultiView1.DataBind();
}

public int test()
{
    return 0;
}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top