469,898 Members | 1,587 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,898 developers. It's quick & easy.

Create an IFRAME Dynamically

Is there a way to create an IFRAME dynamically via VB.NET. In other words
creating the HTML element in the server side code?

thanks in advance....

Nov 19 '05 #1
5 9080
"=?Utf-8?B?QW5nZWw=?=" <An***@discussions.microsoft.com> wrote in
news:0D**********************************@microsof t.com:
Is there a way to create an IFRAME dynamically via VB.NET. In other
words creating the HTML element in the server side code?


I use a literal control to write out the IFrame's code.

--
Lucas Tam (RE********@rogers.com)
Please delete "REMOVE" from the e-mail address when replying.
http://members.ebay.com/aboutme/coolspot18/
Nov 19 '05 #2
Thanks Lucas can you give me an example...

thanks

"Lucas Tam" wrote:
"=?Utf-8?B?QW5nZWw=?=" <An***@discussions.microsoft.com> wrote in
news:0D**********************************@microsof t.com:
Is there a way to create an IFRAME dynamically via VB.NET. In other
words creating the HTML element in the server side code?


I use a literal control to write out the IFrame's code.

--
Lucas Tam (RE********@rogers.com)
Please delete "REMOVE" from the e-mail address when replying.
http://members.ebay.com/aboutme/coolspot18/

Nov 19 '05 #3
"=?Utf-8?B?QW5nZWw=?=" <An***@discussions.microsoft.com> wrote in
news:93**********************************@microsof t.com:
Thanks Lucas can you give me an example...

thanks

"Lucas Tam" wrote:
"=?Utf-8?B?QW5nZWw=?=" <An***@discussions.microsoft.com> wrote in
news:0D**********************************@microsof t.com:
> Is there a way to create an IFRAME dynamically via VB.NET. In other
> words creating the HTML element in the server side code?


I use a literal control to write out the IFrame's code.

dim _lit as literal = new literal
_lit.text = "<IFRAME...>"

PlaceHolder.controls.add(_lit)
--
Lucas Tam (RE********@rogers.com)
Please delete "REMOVE" from the e-mail address when replying.
http://members.ebay.com/aboutme/coolspot18/
Nov 19 '05 #4
Using a LiteralControl is a good solution but depending on what you need to
do, you may consider using an HtmlGenericControl instead. The primary
difference is that the LiteralControl is exactly what it sounds
like...literal. LiteralControls should be used when the control's contents
do not need any server-side manipulation beyond its creation.

With LiteralControl, the entire tag (name, attributes, and applicable
content) needs to be set to the Text property either directly or through the
constructor. If you want to dynamically change any portion of the control,
you need to rewrite the entire tag with the new value. In the case of an
IFRAME, if you wanted to dynamically changing the src attribute requires
rewriting the whole IFRAME tag.

HtmlGenericControl allows for a bit more flexibility in that you specify the
tag name either directly through the TagName property or the constructor and
you set the attributes individually through the Attributes collection.
HtmlGenericControl allows a bit more control since the tag is only
constructed when the control is rendered.

Note that the LiteralControl class is located in the System.Web.UI namespace
and the HtmlGenericControl class is located in the
System.Web.UI.HtmlControls namespace.

My preference is that I only use LiteralControl when I don't need to set
attributes. I only use LiteralControl in three scenarios:
1.) I need to write straight text
2.) I'm dynamically writing a simple tag such as STRONG or BR
[HtmlGenericControl actually renders <br></br> here]
3.) I know that I won't need to change any of the dynamic tag's content.
In all other cases, I like to use the control that provides the closest fit
to the tag I need to render.

The needs of your application should dictate which option you choose. I
just wanted to present a possible alternative.

HTH
----------------
Dave Fancher
http://www.davefancher.com

"Lucas Tam" <RE********@rogers.com> wrote in message
news:Xn***************************@127.0.0.1...
"=?Utf-8?B?QW5nZWw=?=" <An***@discussions.microsoft.com> wrote in
news:0D**********************************@microsof t.com:
Is there a way to create an IFRAME dynamically via VB.NET. In other
words creating the HTML element in the server side code?


I use a literal control to write out the IFrame's code.

--
Lucas Tam (RE********@rogers.com)
Please delete "REMOVE" from the e-mail address when replying.
http://members.ebay.com/aboutme/coolspot18/

Nov 19 '05 #5
....as a follow up, one reason I suggest the HtmlGenericControl is that if
you define the IFRAME in your aspx (or ascx) and set runat="server", the
control is represented server-side as an instance of HtmlGenericControl. Of
course, you'll need to define the control in your code-behind but once done,
you'll have access to its properties through the attributes collection.
This way, rather than defining a place holder (or some other container) and
forcing the LiteralControl into it, you already have its location defined
and may dynamically set its attributes at run-time.
HTH
----------------
Dave Fancher
http://www.davefancher.com

"Dave Fancher" <da**@remove.davefancher.com> wrote in message
news:mP********************@comcast.com...
Using a LiteralControl is a good solution but depending on what you need
to do, you may consider using an HtmlGenericControl instead. The primary
difference is that the LiteralControl is exactly what it sounds
like...literal. LiteralControls should be used when the control's
contents do not need any server-side manipulation beyond its creation.

With LiteralControl, the entire tag (name, attributes, and applicable
content) needs to be set to the Text property either directly or through
the constructor. If you want to dynamically change any portion of the
control, you need to rewrite the entire tag with the new value. In the
case of an IFRAME, if you wanted to dynamically changing the src attribute
requires rewriting the whole IFRAME tag.

HtmlGenericControl allows for a bit more flexibility in that you specify
the tag name either directly through the TagName property or the
constructor and you set the attributes individually through the Attributes
collection. HtmlGenericControl allows a bit more control since the tag is
only constructed when the control is rendered.

Note that the LiteralControl class is located in the System.Web.UI
namespace and the HtmlGenericControl class is located in the
System.Web.UI.HtmlControls namespace.

My preference is that I only use LiteralControl when I don't need to set
attributes. I only use LiteralControl in three scenarios:
1.) I need to write straight text
2.) I'm dynamically writing a simple tag such as STRONG or BR
[HtmlGenericControl actually renders <br></br> here]
3.) I know that I won't need to change any of the dynamic tag's
content.
In all other cases, I like to use the control that provides the closest
fit to the tag I need to render.

The needs of your application should dictate which option you choose. I
just wanted to present a possible alternative.

HTH
----------------
Dave Fancher
http://www.davefancher.com

"Lucas Tam" <RE********@rogers.com> wrote in message
news:Xn***************************@127.0.0.1...
"=?Utf-8?B?QW5nZWw=?=" <An***@discussions.microsoft.com> wrote in
news:0D**********************************@microsof t.com:
Is there a way to create an IFRAME dynamically via VB.NET. In other
words creating the HTML element in the server side code?


I use a literal control to write out the IFrame's code.

--
Lucas Tam (RE********@rogers.com)
Please delete "REMOVE" from the e-mail address when replying.
http://members.ebay.com/aboutme/coolspot18/


Nov 19 '05 #6

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

2 posts views Thread by Patrick Marti | last post: by
3 posts views Thread by Null | last post: by
2 posts views Thread by macca | last post: by
2 posts views Thread by Andy Sutorius via DotNetMonster.com | last post: by
5 posts views Thread by maya | last post: by
reply views Thread by Salome Sato | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.