Vishwamohan

Welcome to Vishwa's blog - Technology, Spirituality and More...

Using IFRAME in ASP.NET

If you are using an IFRAME in ASP.NET and setting the height and width and not working as per your need. Spent couple of hours trying all possible options and found a very easy solution

1. Remove following line from Page

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
2. How to Set values Dynamically

<iframe id="Testframe" runat="Server" />

<script language="vb" runat="server">

 
Protected WithEvents frame1 As System.Web.UI.HtmlControls.HtmlGenericControl
  
  Sub Page_Load()
      Dim frame1 As HtmlControl = CType(Me.FindControl("TestFrame"), HtmlControl)
      With frame1
          .Attributes("src") = "TestPage.aspx"
          .Attributes("width") = "100%"
          .Attributes("height") = "100%"
      End With
      
  End Sub
 
</script>
Loading