Question

Given the following code below. How might I display another web page or content within the placeholder via a server onClick event in C# code; similar to now defunct iframe. I perfer to handle all events via sever side code (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>

Thank you in advance!

Was it helpful?

Solution

You can use WebClient to receive a page from a URI. (It can also send content to a URI too.)

<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));
}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top