1

multiview在 asp.net 中使用一个控件,并且在ActiveViewChanged 事件中我想以编程方式设置默认按钮,从所选视图开始,所以我使用代码:

if(myMultiview.GetActiveview() == myView)
   this.Page.Form.DefaultButton = btnDefault.UniqueID;

这里btnDefault是存在的myView,即使它抛出异常'System.NullReferenceException'

请建议我解决方案

4

1 回答 1

0

我有类似的问题,我试试这个,

    <asp:Panel id="myPanel" runat="server" DefaultButton="ButtonID">
    <asp:MultiView ID="MultiView1" runat="server"  ActiveViewIndex="0">
        <asp:View ID="View1" runat="server" >
            <asp:Button ID="Button1" runat="server" Text="Button" onclick="Button1_Click" />
        </asp:View>
        <asp:View ID="View2" runat="server">
            <asp:Button ID="Button2" runat="server" Text="Button" onclick="Button2_Click" />
        </asp:View>
    </asp:MultiView>
    </asp:Panel>

</div>
</form>
protected void Page_Load(object sender, EventArgs e)
    {
        myPanel.DefaultButton = "Button1";
    }
    protected void Button1_Click(object sender, EventArgs e)
    {
        Response.Write("View1 Button is clicked");
        MultiView1.ActiveViewIndex = 1;
        myPanel.DefaultButton = "Button2";
    }
    protected void Button2_Click(object sender, EventArgs e)
    {
        Response.Write("View2 Button is clicked");
        MultiView1.ActiveViewIndex = 0;
    }

可能会帮助你。

于 2013-05-24T10:05:26.197 回答