Click here to Skip to main content
15,891,184 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I am trying to modify or add the "src" attribute of the an Iframe from code behind file but unable to do so.
.aspx:-
XML
<iframe id="Iframe1">
</iframe>

.cs:-
C#
HtmlLink link1 = (HtmlLink)Page.FindControl("Iframe1");
link1.Attributes.Add("src", "http://www.xyz.com");

The error I am getting:
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.NullReferenceException: Object reference not set to an instance of an object.
Posted
Updated 13-Nov-11 3:46am
v3

Your code is wrong, try like this,
C#
HtmlControl frame1 = (HtmlControl)this.FindControl("Iframe1");
frame1.Attributes["src"] = "http://www.xyz.com";


BTW check this Loading pages in IFRAME dynamically from codebehind - ASP.NET[^]
 
Share this answer
 
C#
HtmlControl x = (HtmlControl)this.frame1;
           

x.Attributes.Add("src", "http://www.xyz.com"])
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900