how to assign src attribute dynamically of iframe in asp.net 2.0 content page

849 views
Skip to first unread message

yogi

unread,
Apr 11, 2008, 9:55:51 AM4/11/08
to DotNetDevelopment, VB.NET, C# .NET, ADO.NET, ASP.NET, XML, XML Web Services,.NET Remoting
hi guys,
i want to know how to assign src attribute dynamically of iframe in
asp.net 2.0 content page.
so please help me.

Cerebrus

unread,
Apr 11, 2008, 12:29:03 PM4/11/08
to DotNetDevelopment, VB.NET, C# .NET, ADO.NET, ASP.NET, XML, XML Web Services,.NET Remoting
C#:
----
MyIFrame.Attributes["src"] = "http://mysite.com/mypage.aspx";

VB:
----
MyIFrame.Attributes("src") = "http://mysite.com/mypage.aspx"

yogi

unread,
Apr 12, 2008, 1:42:35 AM4/12/08
to DotNetDevelopment, VB.NET, C# .NET, ADO.NET, ASP.NET, XML, XML Web Services,.NET Remoting
hi cerebrus

thanks for your reply

but your given code dosen't work in content pages of asp.net 2.0

i was tride this code before. for e.g.

1>in code behind :

HtmlControl frame4 = (HtmlControl)this.FindControl("frame1");
frame4.Attributes["src"] = "http://gmeail.com";
2>frmae code in html :

<iframe id="frame1" runat="server" width="100%" height="100%" >

</iframe>

the above code showing me an error as object referance not set
an instance of an object

please tell me how i assign as src attribute to iframe from codebehind
in content pages of asp.net 2.0

thanks in advance

Cerebrus

unread,
Apr 12, 2008, 10:19:14 AM4/12/08
to DotNetDevelopment, VB.NET, C# .NET, ADO.NET, ASP.NET, XML, XML Web Services,.NET Remoting
The code is flawless, however, it doesn't work (for you) because you
are unable to "find" the IFrame in your case.

I don't see why you have to do a FindControl. You can simply refer to
it using the ID. It will be of the type HtmlGenericControl :

frame1.Attributes["src"]

AstroDrabb

unread,
Apr 14, 2008, 10:21:12 AM4/14/08
to DotNetDe...@googlegroups.com
Is your IFrame in the master page?  Then you need to use Master and not "this".
For example I made a simple master page with a label and a menu.  To get to
those controls I use:

((Label)Master.FindControl("lblHeader")).Text = "Test";
((Menu)Master.FindControl("Menu1")).Items[0].ChildItems[0].Selected = true;

So maybe try:

HtmlControl frame4 = (HtmlControl)Master.FindControl("frame1");

JimDaGeek

Reply all
Reply to author
Forward
0 new messages