Groups > Asp .Net > HttpHandlers and HttpModules > Re: removing ContentPlaceHolder dynamically in masterpage using HttpModule




Re: removing ContentPlaceHolder dynamically in masterpage
using HttpModule

Re: removing ContentPlaceHolder dynamically in masterpage using HttpModule
Sat, 15 Mar 2008 18:47:10 +000
Hi Chris 

Thanks a lot for replying. Infact I wrote this module after watching your 
geekspeak webcast on MSDN :) 

I would appreciate if you could clarify more, why is this not possible ? 

Here is what I am trying to achieve: 

 I am trying to make the master page consistent across all pages in 
sharepoint, and since some of the admin pages have two extra 
contentplaceholders (since they have diff. master page) than default master 
page, I am trying to get rid of those extra placeholders. 

I cannot modify the Page class neither the master page since they are both 
inbuilt in sharepoint . 

If I am able to achieve this, I would have a httpmodule which can be just 
plugged to provide consistent look and feel for sharepoint 2007. 

Thanks, 
Madhur 

 wrote in message news:2235083@forums.asp.net... 
> You are not going to ahve this type of access to the content in an 
> httpModule. You should think about subclassing the Page class with a 
> method to remove the control from within it. 
>
Post Reply
removing ContentPlaceHolder dynamically in masterpage using HttpModule
Sat, 15 Mar 2008 18:49:35 +000
Hi All
 I am trying to remove one specific contentplaceholder dynamically using
HttpModule. At line no. 52, the main line which causes removes executes. The
problem is although this line executes successfully under debugger, it gives
index outof range exception when running normally. Can anyone give me hints on
why this could be happening. ? The sharepoint specific code in the event handler
can be ignored 
 Below is code I am using:   

1    using System;
2    using System.Web;
3    using System.Web.UI;
4    using System.Web.UI.WebControls;
5    using Microsoft.SharePoint;
6    namespace LayoutsHandler
7    {
8    public class LayoutsHandler: System.Web.IHttpModule
9        {
10           HttpApplication app;
11   
12   #region IHttpModule Members
13   
14   void System.Web.IHttpModule.Dispose()
15           
17   
18   void System.Web.IHttpModule.Init(System.Web.HttpApplication context)
19           {
20               app = context;
21               app.PostMapRequestHandler += new
EventHandler(app_PostMapRequestHandler);
22           }
23   
24   void app_PostMapRequestHandler(object sender, EventArgs e)
25           {
26               Page page = HttpContext.Current.CurrentHandler as Page;
27   if(page!=null)
28                   page.PreInit += new EventHandler(pagehandler_PreInit);
29   
30   
31           }
32   
33   void pagehandler_PreInit(object sender, EventArgs e)
34           {
35   
36               Page page = sender as Page;
37   if (page == null) return;
38   if (page.MasterPageFile == null) return;
39               HttpContext context = HttpContext.Current;
40   string currUrl = context.Request.Url.ToString();
41   string basepath = "http://" + context.Request.Url.Host
+":"+ context.Request.Url.Port.ToString();
42   
43               currUrl = context.Request.RawUrl;
44               if (currUrl.ToLower().Contains("/_layouts/")
&&
45              
page.MasterPageFile.ToLower().EndsWith("application.master"))
46               {
47                   currUrl = currUrl.Substring(0,
currUrl.ToLower().IndexOf("/_layouts/"));
48                   SPSite site = new SPSite(basepath + currUrl);
49                   SPWeb web = site.OpenWeb(currUrl);
50   
51   
52                   Control ctrl =
page.Controls[0].Controls[0].Controls[3].FindControl("PlaceHolderPageDescri
ptionRowAttr");
53                   page.Controls.Remove(ctrl);
54   
55                   page.MasterPageFile = web.MasterUrl;
56                   web.Dispose();
57                   site.Dispose();
58               }
59           }
60   
61   #endregion
62       }
63   }
64
Post Reply
Re: removing ContentPlaceHolder dynamically in masterpage using HttpModule
Sat, 15 Mar 2008 21:40:26 +000
You are not going to ahve this type of access to the content in an httpModule.
You should think about subclassing the Page class with a method to remove the
control from within it.
Post Reply
Re: removing ContentPlaceHolder dynamically in masterpage using HttpModule
Sun, 16 Mar 2008 20:29:13 +000
Well you wont have access to the controls like you are trying because the module
does not access or really process the request like the page handler does. It
would really only have access to the content being sent to the browser. So to do
what you are wanting to do will require a lot of manipulation at run-time I
think. :> Not sure how to answer this completely, but I think you would be
better off controlling things from within SharePoint itself. I am still not
versed enough in SP to give a good answer on this, sorry.
Post Reply
about | contact