title: What is the best way of setting the src of an iframe from a codebehind file in ASP.NET?
body: <p>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:</p>
  
  <pre><code>&lt;iframe id="dynamicframe" runat="server"&gt;&lt;/iframe&gt;
  </code></pre>
  
  <p>Should I set it directly in the codebehind like so:</p>
  
  <pre><code>dynamicframe.Attributes["src"] = "http://dynamicurl.com";
  </code></pre>
  
  <p>Or should I create a property in the codebehind and reference it in the iframe:</p>
  
  <pre><code>&lt;iframe id="dynamicframe" src="&lt;%= dynamicFrameUrl %&gt;"&gt;&lt;/iframe&gt;
  </code></pre>
  
  <p>Or some other method altogether?</p>