鉴于以下代码。如何通过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>
提前谢谢!
答案 0 :(得分: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));
}