In this article i will show you how you can set how you can dynamically set the iframe src in your asp.net application using c#.net. In this first we will create a new asp.net application and add a web page. In this webpage we will add and iframe and add server tag which Is runat=”server”.
|
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="WebForm1.aspx.cs" Inherits="WebApplicationTest.WebForm1" %>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml"> <head runat="server"> <title></title> </head> <body> <form id="form1" runat="server"> <div> <iframe runat="server" id="ifrDisplay"></iframe> </div> </form> </body> </html> |
Please check the above code above highlighted piece of code. Now this iframe control is accessible on server side code of your application.
Now add a new page which we will display in iframe. Here is the test page.
Now we will write code to access the test page and display it on iframe control.
|
using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.Web.UI; using System.Web.UI.WebControls;
namespace WebApplicationTest { public partial class WebForm1 : System.Web.UI.Page { protected void Page_Load(object sender, EventArgs e) { ifrDisplay.Src = "TestPage.aspx"; } } } |
Now we have done run the application and check the output.




0 comments:
Please let me know your view