Create an IFRAME Dynamically

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

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....
 
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.
 
Thanks Lucas can you give me an example...

thanks


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

PlaceHolder.controls.add(_lit)
 
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
 
....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 said:
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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top