What is the best way to install src iframe from codebehind file in ASP.NET?

I have an iframe with a dynamic URL based on the results of a web API call. What is the best way to install src on an aspx page? Here is an iframe example:

<iframe id="dynamicframe" runat="server"></iframe>

Should I install it directly in codebehind like this:

dynamicframe.Attributes["src"] = "http://dynamicurl.com";

Or I need to create a property in code and specify it in an iframe:

<iframe id="dynamicframe" src="<%= dynamicFrameUrl %>"></iframe>

Or some other method at all?

+5
source share
2 answers

This is a general question that may be the same for any html tag.

An alternative third option is to use a literal control and completely display the iframe on the code behind:

 txtLiteral.Text = "string.Format(
      "<iframe id=\"dynamicfrmae\" src=\"{0}\"></iframe>",   PageUrlForSrc  );

Different for all methods:

Direct recording on page <%= %>

  • Do not work with the update panel
  • , ( ).

, . , , responce.flush() .

,

  • UpdatePanel

  • html
  • ,
  • , .

, , .

+3

, URL-, , , . , , ?

0

All Articles