Note that there are some explanatory texts on larger screens.

plurals
  1. POGetting reference to server controls when handler is MvcHandler
    text
    copied!<p>I am working working on an httpmodule to hide certain content on my website if certain criteria are not met. My handler setup is pretty simple. Here are the relevant parts to my question:</p> <pre><code>Public Interface IFeatureItem Property ID As Guid Sub FeatureItemPreRenderComplete(ByVal sender As Object, ByVal e As EventArgs) End Interface Public Class MyModule Implements System.Web.IHttpModule Public Sub Init(ByVal context As System.Web.HttpApplication) Implements System.Web.IHttpModule.Init AddHandler context.PreRequestHandlerExecute, AddressOf Application_PreRequestHandlerExecute End Sub Private Sub Application_PreRequestHandlerExecute(ByVal source As Object, ByVal e As EventArgs) If TypeOf source Is HttpApplication Then Dim Application As HttpApplication = source If TypeOf Application.Context.Handler Is Page Then Dim Page As Page = Application.Context.Handler AddHandler Page.PreRenderComplete, AddressOf FeatureItemPreRenderComplete ElseIf TypeOf Application.Context.Handler Is System.Web.Mvc.MvcHandler Then Dim MvcHandler As System.Web.Mvc.MvcHandler = Application.Context.Handler &lt;What do I do here&gt; End If End If End Sub Private Sub FeatureItemPreRenderComplete(ByVal source As Object, ByVal e As System.EventArgs) Dim Page As Page = source Dim Repository As IFeatureRepository = GetRepository(Page.Application) 'Holds supported IFeature Dim IFeatureItems As IEnumerable(Of IFeatureItem) = GetIFeatureItems(Page) 'Goes through Page's control tree and returns IFeatureItems For Each IFeatureItem In IFeatureItems Dim FeatureEventArgs As FeatureEventArgs = New FeatureEventArgs(IFeatureItem.ID, FeatureAllowed(IFeatureItem.ID, Repository)) IFeatureItem.FeatureItemPreRenderComplete(Me, FeatureEventArgs) Next End Sub &lt;Irrelevant stuff removed&gt; End Class </code></pre> <p>Basically setting up event handlers on the page object if the handler is a page. Then in the PreRenderEvent I loop through all the IFeatureItems on the page and call a method in IFeatureItem. This works great if the handler is a page. </p> <p>This site has an mvc view for a dashboard and also contains webforms controls that could be an IFeatureItem. What I want to do is loop through the webforms controls in this view and do the same processing on them as I would on a normal page, but I can't figure out a way to do so and have had no luck googling. Is this possible within a module? Is PreRequestHandlerExecute the right event to set up my event handlers?</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload