I have an iframe that has a dynamic URL based on the results of web API call. What is the best way of setting its src in the aspx page? Here is an example of the iframe:
<iframe id="dynamicframe" runat="server"></iframe>
Should I set it directly in the codebehind like so:
dynamicframe.Attributes["src"] = "http://dynamicurl.com";
Or should I create a property in the codebehind and reference it in the iframe:
<iframe id="dynamicframe" src="<%= dynamicFrameUrl %>"></iframe>
Or some other method altogether?
This is a general question that can stands the same for any html tag.
The alternative third option is to use a literal control and fully render the iframe on code behind as:
The different for all methods :
Direct write on page
<%= %>This is the method that I avoid most. I use it only when I like to left some calculations for later and avoid page cycle, or when I have
responce.flush()just before it.Write it using to literal
Write it as attribute on code behind
All methods have their purpose, and I used then according what they fit best.