How to open a web site inside the webpage in asp.net c#

Many times, we want to show/open a website inside of web page, for this we need to use <iframe> control. We can open website/ web page to pass the url .
Source Code:-
<%@ 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>open a website using iframe</title>
</head>
<body>
    <form id="form1" runat="server">
    <fieldset style="width:1024px;">
        <legend>Open a web site in iframe </legend>


        <asp:DropDownList ID="DropDownList1" runat="server">
            <asp:ListItem>http://</asp:ListItem>
            <asp:ListItem>https://</asp:ListItem>
        </asp:DropDownList>
        <asp:TextBox ID="txturl" runat="server" placeholder="Please enter your website url"></asp:TextBox>
        <asp:Button ID="btnsubmit" runat="server" Text="GO "
            onclick="btnsubmit_Click" />
    </fieldset>

    <iframe id="frame1" width="1024px" height="786px" runat="server" visible="false"/>
    </form>
</body>
</html>

Code behind(C#):-
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;

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


    }

    protected void btnsubmit_Click(object sender, EventArgs e)
    {
        HtmlControl frame1 = (HtmlControl)this.FindControl("frame1");
        frame1.Visible = true;
        string text = DropDownList1.Text + txturl.Text;
        frame1.Attributes["src"] = text;
    }
} 




Out-Put:-




How to open a web site inside the webpage in asp.net c# How to open a web site inside the webpage in asp.net c# Reviewed by NEERAJ SRIVASTAVA on 6:06:00 PM Rating: 5

No comments:

Powered by Blogger.