1

给出下面的代码。如何通过 C# 代码中的服务器 onClick 事件在占位符内显示另一个网页或内容;类似于现在已失效的 iframe。我更喜欢通过服务器端代码(C#,asp.net 4.0)处理所有事件

<asp:Content ID="Content1" ContentPlaceHolderID="head" Runat="Server"></asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="MainContentPlaceHolder" 
runat="Server">
   <asp:PlaceHolder runat="server" ID="PlaceHolder1">  
</asp:PlaceHolder>
</asp:Content>
<asp:Content ID="Content3" ContentPlaceHolderID="NavigationContentPlaceHolder" Runat="Server">
<uc1:NavigationUserControl runat="server" ID="NavigationUserControl" />
</asp:Content>

先感谢您!

4

1 回答 1

2

您可以使用WebClient从 URI 接收页面。(它也可以将内容发送到 URI。)

<asp:Button runat="server" ID="Button1" OnClick="Button1_Click" 
   Text="Load Page"/>
<asp:PlaceHolder runat="server" ID="PlaceHolder1">
</asp:PlaceHolder>

protected void Button1_Click(object sender, EventArgs e)
{
    var uri = new Uri("http://www.stackoverflow.com");
    var result = new WebClient().DownloadString(uri);
    PlaceHolder1.Controls.Add(new LiteralControl(result));
}
于 2013-11-20T19:08:11.240 回答