Feb 19, 2008

Accesing Master Page With IFRAME Property From Code Behind

Sometimes we need to access code front controls property from code behind, so that we can create a dynamic or configuration variable for this purpose.

How we know what property we have in the code front controls?
In the code front, we can get intellisense helps to verify whether it is a syntax or property with different colors.

ASP.NET Code Front:

(asp:Content ID="Content3" ContentPlaceHolderID="MainContent" runat="Server")
(iframe id="mainContent" name="mainContent" src="../Dev.aspx" width="700px"
scrolling="auto" frameborder="0" marginheight="0" marginwidth="0" runat="server"
title="E-Application Content")(/iframe)
(/asp:Content)

** replace ( to < ** replace ) to >


ASP.NET Code Behind:

Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
mainContent.Attributes.Add("Height", "700px")
End Sub


Explanation:
IFRAME ASP.net Code behind having an "Attribute" syntax where we can simply accessing the value of controls in front page. Yet, code front control needed to be "runat=server" mode.

We created a master page, within the master page we have content place holder setup.
Then we create a new page and inherits master page layout.

In this case, we might still need to use traditional html href link to open a page onto a target.
We can use IFRAME with the id and NAME ( name is needed here ) and shown the page on the IFRAME.

With the code above, we can manipulate IFRAME property during page load.

No comments:

Post a Comment