chuang4630
asked on
How do I dynamically embed the iframe into the ASP.NET code?
How do I dynamically embed the iframe into the ASP.NET code?
For example, area A is a frame (iframe id = myFrame), and area B reguar webform.
How do I change the iframe src in area A dynamically (in the code behind)?
For example, area A is a frame (iframe id = myFrame), and area B reguar webform.
How do I change the iframe src in area A dynamically (in the code behind)?
ASKER
But I cannot find iframe control in ASP.NET.
<asp:iframe id="myFrame" runat="Server"></asp>
or
<iframe id="myFrame" runat="Server"></iframe>
???
I am away from my development PC so just cannot test it. Do you have tested code to share?
Thanks,
<asp:iframe id="myFrame" runat="Server"></asp>
or
<iframe id="myFrame" runat="Server"></iframe>
???
I am away from my development PC so just cannot test it. Do you have tested code to share?
Thanks,
ASKER
I mean sample code?
in HTML
<iframe id="myIframe" runat="server" visible="true" width="400px" height="600px"></iframe>
In code behind
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
Dim iFrameControl As HtmlControl = CType(Me.FindControl("myIf rame"), HtmlControl)
iFrameControl.Attributes.A dd("src", "http://google.ca")
End sub
once your page load the iframe will load google.ca
HTH
<iframe id="myIframe" runat="server" visible="true" width="400px" height="600px"></iframe>
In code behind
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
Dim iFrameControl As HtmlControl = CType(Me.FindControl("myIf
iFrameControl.Attributes.A
End sub
once your page load the iframe will load google.ca
HTH
ASKER
May I see the "Register" Line (in HTML)?
ASKER
Are you creating the user control?
there are not asp:somecontrol versions for every html tag out there, iframe is one of them. For controls like this, you can still add an id/runat="server", and if you wanted to use them in code, they are considered a HtmlGenericControl
ASKER
I received a runtime error: Object reference not set to an instance of an object. And point to the line of
frameTop.Attributes["src"] = "http://search.msn.com";
What is wrong with the code?
Here is the code:
//protected System.Web.UI.HtmlControls .HtmlGener icControl frameTop;
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
HtmlControl frameTop = (HtmlControl)this.FindCont rol("frame Top");
frameTop.Attributes["src"] = "http://search.msn.com";
}
}
<asp:Content ID="Content2" ContentPlaceHolderID="TopA rea" Runat="Server">
<iframe id="frameTop" runat="Server" title = "SOMETHING" width = 100%></iframe>
</asp:Content>
frameTop.Attributes["src"]
What is wrong with the code?
Here is the code:
//protected System.Web.UI.HtmlControls
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
HtmlControl frameTop = (HtmlControl)this.FindCont
frameTop.Attributes["src"]
}
}
<asp:Content ID="Content2" ContentPlaceHolderID="TopA
<iframe id="frameTop" runat="Server" title = "SOMETHING" width = 100%></iframe>
</asp:Content>
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Thanks
...
myIframe.attributes.add("s