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.
<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");
}
Comments
Post a Comment