Easily Integrate IFrame in ASP.NET

An IFrame (Inline Frame) is an HTML document embedded inside another HTML document on a website. The IFrame HTML element is often used to insert content from another source, such as an advertisement, into a Web page.

In this article, I will show you how to integrate IFrame in ASP.NET. Checkout following code snippet.


<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Iframe.aspx.cs"
Inherits="Iframe" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
 "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
   <title>Untitled Page</title>
</head>
<body>
   <form id="form1" runat="server">
       <div>
           <asp:Panel ID="Panel1" runat="server">
               <asp:TextBox ID="URL" runat="server" Text="http://" />
               <asp:Button ID="Button1" Text="Go" OnClick="GetURL" runat="server" />
               <iframe id="Iframe1" src="<%# TheURL %>" runat="server" frameborder="0" marginwidth="1"
                   style="position: absolute;top:100px;width:800px;height:400px;border:solid 1 px"></iframe>
           </asp:Panel>
       </div>
   </form>
</body>
</html>
using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;

public partial class Iframe : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {

    }
    public string TheURL = "";

    public void GetURL(object Src, EventArgs Args)
    {
        if (!(URL.Text == "http://"))
        {
            TheURL = URL.Text;
            Page.DataBind();
        }
    }

}

Post a Comment

Please do not post any spam link in the comment box😊

Previous Post Next Post

Blog ads

CodeGuru