Asp.net programming we consider all important topic for knowledge about controls,web Services, JSON, Ajax, database, and interview related Question. In this Asp.net and sql server tutorial blog we give many examples of jquery as like How Play YouTube Video in Your Asp.net Website by URL, How to Play YouTube Videos in Asp.net by using Jquery , Jquery Change div background on mouseover in asp.net , JQuery UI Datepicker (Calendar) etc.

Saturday, February 7, 2015

in Asp.net open a page in Iframe from code behind Asp.net with C#

open a page in Iframe from code behind Asp.net with C#:



Most of us who develop Web Applications would have used an IFRAME during some stage of our lives. IFRAME's are an easy way by which you can embed another page within your original page such that you can show some important information like Stock position/Weather from another site without worrying about the changes happening to that site and updating the same. The Frame can also be used to show another page from your own application.

ASP.NET also provides the option to have an IFRAME in our ASPX Pages. It can be with/without the "runat=server" attribute and does serve the purpose of embedding the page. The source for the frame can be set as follows:-

<IFRAME id="frame1" src="SourcePage.extension / URL of the external Site" scrolling="auto">
</IFRAME>

However, in practical scenarios, we may want to load the page dynamically. In other words, we may want to specify the "src" attribute (the page which we want to show), dynamically. There is no straight forward way to do that and even if you add a "runat=server" attribute to it (though required in the work around provided below), you cannot access the "src" property directly.

The workaround to do that is as follows:-


1. Specify the "runat=server" attribute as follows in the ASPX Page:-

<IFRAME id="frame1" scrolling="auto" runat="server">
</IFRAME>
C#  code for give url dynamically:
HtmlControl frame1 = (HtmlControl)this.FindControl("frame1");
frame1.Attributes["src"] = "http://www.live.com" ;

 Some time we found tipical problem with iframe as like : we discuss a problem here
I have a single page with a datagrid (on the left hand side) and an iframe (on the right hand side). The datagrid is filled with all vehicles' data from database, while the iframe is filled with a Google map to plot these vehicles.  

The iframe actually loads another page to do the plotting.


I am refreshing the datagrid on timer tick. But, the iframe is not getting refreshed at the same time. So, the map is not getting plotted again with new data. How do I change the iframe src from code behind page on timer tick event.



When we search this problem in internet we got fallowing Ans:

<iframe height="450px" width="450px" scrolling="auto" runat="server" id="iFrame1" />
protected void Page_Load(object sender, EventArgs e)
{
    string Url = "TXT/business applications_en.htm";
    //iFrame1.Attributes["src"] = Url;
    System.Web.UI.AttributeCollection aCol = iFrame1.Attributes;
    aCol.Add("src", "Test\test.aspx");

No comments:

Post a Comment