javascript 如何在 asp.net 中创建多视图控件并在运行时对其进行操作?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/16931000/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-27 06:30:07  来源:igfitidea点击:

How to create a multiview control in asp.net and manipulate it at run time?

c#javascriptjqueryasp.net

提问by Chris N.P.

Example:

例子:

<asp:MultiView
        id="MultiView1"
        ActiveViewIndex="1"
        Runat="server">
        <asp:View ID="View1" runat="server" >
            <iframe id="v1" runat="server" src='http://www.w3schools.com' style="border: None; height: 100%; width: 100%;"></iframe>
        </asp:View>        
        <asp:View ID="View2" runat="server">
            <iframe id="Iframe1" runat="server" src='http://www.w3schools.com/html/html5_intro.asp' style="border: None; height: 100%; width: 100%;"></iframe>
        </asp:View>        
        <asp:View ID="View3" runat="server">
            <br />This is the third view
            <br />This is the third view
            <br />This is the third view
            <br />This is the third view
        </asp:View>
        <asp:View ID="View4" runat="server">
            <br />This is the third view
            <br />This is the third view
            <br />This is the third view
            <br />This is the third view
        </asp:View>        
    </asp:MultiView>

Concerns:

关注点:

  1. How to create this multiview structure at run time?
  2. Is there any alternative for iframe that can be use inside multiview?
  3. Can I use one multiview view for say 2 or more menu?
  4. How to reference and manipulate multiview using javascript or jquery?
  1. 如何在运行时创建这个多视图结构?
  2. 是否有可以在多视图中使用的 iframe 的替代方案?
  3. 我可以使用一个多视图视图来表示 2 个或多个菜单吗?
  4. 如何使用 javascript 或 jquery 引用和操作多视图?

Please help me with this.

请帮我解决一下这个。

Thank you!

谢谢!

回答by Sean Petiya

The answer to this is similar to your last question: How to Show/Hide Menu Item and how to create it at run time?. You may also want to look at this MSDN article for a discussion regarding adding controls programmatically: http://msdn.microsoft.com/en-us/library/kyt0fzt1(v=vs.100).aspx

对此的答案类似于您的上一个问题:如何显示/隐藏菜单项以及如何在运行时创建它?. 您可能还想查看这篇 MSDN 文章,以了解有关以编程方式添加控件的讨论:http: //msdn.microsoft.com/en-us/library/kyt0fzt1(v=vs.100).aspx

Below is an example of how to populate a MultiViewcontrol with Viewcontrols dynamically.

下面是如何MultiViewView控件动态填充控件的示例。

protected void Page_Init(object sender, EventArgs e)
{
    // Create View.
    View myView = new View();

    // Create controls.
    Label myLabel = new Label();
    myLabel.Text = "<b>Test</b>";

    // Add controls to View.
    myView.Controls.Add(myLabel);


    //Add view to MultiView.
    MultiView1.Views.Add(myView);
    MultiView1.ActiveViewIndex = 0;
}

The above logic is the same for adding any controls to a page programmatically.

上述逻辑与以编程方式向页面添加任何控件的逻辑相同。

You can manipulate the MultiViewcontrol the same way using server-side code by referencing specific Views with an index:

您可以MultiView使用服务器端代码以相同的方式操作控件,方法是通过索引引用特定的视图:

Label myLabel = new Label();
myLabel.Text = "<b>Test</b>";

MultiViewDemo.Views[0].Controls(myLabel);

You should then be able to manipulate any HTML elements in those views using jQuery as normal.

然后,您应该能够像往常一样使用 jQuery 操作这些视图中的任何 HTML 元素。

Using multiple Menucontrols in a MultiViewdepends on your requirements.

Menu在一个中使用多个控件MultiView取决于您的要求。

In regards to the iframe, I'm not sure what you would be looking for in an alternative, but you should be able to manipulate your iframecontrols with server-side code since you have added the runat="server"attribute to them.

关于iframe,我不确定您会在替代方案中寻找什么,但是您应该能够iframe使用服务器端代码操作您的控件,因为您已向runat="server"它们添加了属性。