Access Controls which are written by Response.WriteFile(“Sample.htm”)
Question
My aim is to stream a .htm file via Response.WriteFile("Sample.htm");
and then access a specific html element (ex. <a runat="server" id="myAnchor" />
) from the Response which happened in the Page_PreInit
Event.
I tried it already with ((HtmlGenericControl)myAnchor)
but it doesn't work. It only works, if the anchor tag is inside the .aspx page.
Is there a possibility to reinitialize the .aspx
page after the response.write
event happened, so that the anchor tag from the sample.htm
file gets indexed like it would be an anchor tag from the .aspx
page.
Thanks for your help.
Solution
No. Once you write anything directly to the response stream it leaves the web server (where your code is running) and goes directly to the browser. Do not pass 'GO'. Do not collect $200.
Anything in that file is never loaded into your Page class' control tree in the first place, but sent directly to the browser. "reinitialize the .aspx page" wouldn't help you. Instead, to re-use content like this, you need to embed it in a control that can be included on the page or put it in a master page.