Sharepoint 用户控件为;屏幕“;在Web部件中

Sharepoint 用户控件为;屏幕“;在Web部件中,sharepoint,user-controls,web-parts,Sharepoint,User Controls,Web Parts,我正在写我的第一个网页。 我使用一些用户控件作为屏幕。我在这里遇到了麻烦 第一个屏幕包含动态创建的选项(超链接)列表。用户通过单击做出决定后,我想更改屏幕并将一些参数传递到新屏幕 我的决定是加载创建Web部件所需的所有控件。我现在不需要的控件我使其不可见 SomeUserControl1 uc1 = (SomeUserControl1)Page.LoadControl("~/_controltemplates/SomeUserControl1.ascx"); SomeUserCo

我正在写我的第一个网页。 我使用一些用户控件作为屏幕。我在这里遇到了麻烦

第一个屏幕包含动态创建的选项(超链接)列表。用户通过单击做出决定后,我想更改屏幕并将一些参数传递到新屏幕

  • 我的决定是加载创建Web部件所需的所有控件。我现在不需要的控件我使其不可见

        SomeUserControl1 uc1 = (SomeUserControl1)Page.LoadControl("~/_controltemplates/SomeUserControl1.ascx");
        SomeUserControl2 uc2 = (SomeUserControl2)Page.LoadControl("~/_controltemplates/SomeUserControl2.ascx");
        uc2.Visible = false;
    
        Controls.Add(uc1);
        Controls.Add(uc2);
    
  • 第一个用户控件中的选项实现为链接按钮(服务器端)。OnClik事件调用webpart类中的一个特殊方法,在该方法中,我更改了用户控件的可见性,并将一些参数传递给usercontrol2

  • 我不喜欢这种方法。是否有不同的方法来实现所描述的功能


    谢谢

    您需要使用ASP.NET向导控件,它可以做您想要的事情。

    从设计角度看,您所做的事情看起来有点可怕。您应该考虑将各种用户控件嵌套到单个用户控件中,以用作Web部件的外观。保持各种用户控件之间的耦合松散,如果需要处理控件可见性之类的事情,请考虑实现观察者模式