user1173169
user1173169

Reputation:

Use of Page_PreRender to execute C# code when page controls are loaded

I have the following code :

protected void Page_Load(object sender, EventArgs e)
{
  string runat = "runat=\"server\"";    
}

protected void Page_PreRender(object sender, EventArgs e)
{       
//some code       
}

<iframe <%=runat%>></iframe>

I need to be sure the code within Page_PreRender executes only when the variable runat has been initialized & the iframe control is ready for rendering. Unfortunately it does not work. I also tried Page_PreRenderComplete and it does not work.

Does anyone have an idea to fix this problem ? Thanks!

Upvotes: 0

Views: 1391

Answers (1)

Lajos Arpad
Lajos Arpad

Reputation: 76424

Create a PlaceHolder in your markup and then add the iframe programmatically to the PlaceHolder as a LiteralControl, like this:

protected void Page_Load(object sender, EventArgs e)
{
    PlaceHolder1.Controls.Add(new LiteralControl("<iframe src='something.aspx'></iframe>"));
}

Upvotes: 1

Related Questions