This project is read-only.

Hide a Widget Text in posts and pages

Topics: ASP.NET 2.0, Business Logic Layer, Controls, Themes
May 23, 2013 at 4:13 PM
I had the need to have a widget visible on the home page but not visible in the posts and in the pages ..
so I created this line of code in the file site.cshtml, Razor-based BlogEngine.NET
@ If (Request.Url.ToString (). ToLowerInvariant (). Contains ("/ default.aspx"))
                     @ Html.Raw (Html.RenderWidgetZone ("be_WIDGET_ZONE"))
<div id="sidebar-page">
                         @ Html.Raw (Html.RenderWidgetZone ("page-sidebar"))
                    </ Div>
but the loading of page is slightly slower ... there is another solution??

May 23, 2013 at 9:21 PM
hi fab, if you can access to code, try this idea: change code not in the site.master, of your theme, but in page.aspx.cs and post.aspx.cs .
May 23, 2013 at 9:37 PM
mm ok but where? in OnInit?? for example???
May 24, 2013 at 3:49 PM
how do I put exactly knowing where to appear widget?

I want to address is that appears only when just

i must to change.. Request.Url.ToString (). ToLowerInvariant (). Contains ("/ default.aspx"))???

May 24, 2013 at 4:39 PM
i tried this but don't work

@if (Request.Url.ToString()= Utils.AbsoluteWebRoot)


If HttpContext.Current.Request.Url.ToString().ToLower() ==Utils.AbsoluteWebRoot)

can you help me??

the current page must be equal at name of site (example: OR

May 27, 2013 at 9:03 AM
Hi Fab,
I used this code in site.master.cs
protected void Page_Load(object sender, EventArgs e)
        string path = Request.RawUrl.ToLower();
        if (path.LastIndexOf('/') > -1)
            path = path.Substring(path.LastIndexOf('/') + 1);
            if (path.StartsWith("default.aspx") || path.StartsWith("blog.aspx") || path == "") //for default and blog pages
                ctl00_widgetContainer3e8dedc2f18441c8b7196bfea04c86d6_3e8dedc2f18441c8b7196bfea04c86d6_ADOut.Visibile = true; // widget ID
                ctl00_widgetContainer3e8dedc2f18441c8b7196bfea04c86d6_3e8dedc2f18441c8b7196bfea04c86d6_ADOut.Visibile = false;
May 27, 2013 at 11:17 AM
great, but how do I know the ID of the widget to hide or make it appear?

May 27, 2013 at 2:00 PM
via source code . do you have this page on-line?
May 27, 2013 at 2:10 PM
no... i'm making test in local... for example one of my ID Widget is so : widgetff046373-7f0b-4f45-abd9-7c755e55cf45

and it's different by your ID... it's normal?

do you add something?
May 27, 2013 at 4:13 PM
yes, it's normal.
no, i didn't adding anything
May 27, 2013 at 4:44 PM
Great, this evening i will try your solution...

For the moment thank you very very much...

May 27, 2013 at 8:21 PM
Edited May 27, 2013 at 8:24 PM
one of my ID widget in source code is this : bc54b71e-272d-4585-a41b-edef30efbdec, i'm using Razor-based BlogEngine.NET theme...

i obtain this error:

CS0103: The name 'bc54b71e' does not exist in the current context.
Riga 25:             if (path.StartsWith("default.aspx") || path.StartsWith("blog.aspx") || path == "") //for default and blog pages
Riga 26:             {
Riga 27:                 bc54b71e-272d-4585-a41b-edef30efbdec.Visibile = true; // widget ID
Riga 28:             }
Riga 29:             else
What can i do?
May 27, 2013 at 8:39 PM
what is your theme? is a custom theme or one frome the gallery; so we can try to reconstruct your scenario.
May 27, 2013 at 8:40 PM
AllTuts theme...
May 28, 2013 at 1:39 PM
my situation is this... i add a widget texbox and i see this id but i think that isn't ID that use you
<div class="widget textbox"
for example in tags widget i see this situation
<div class="widget tagcloud"
<div class="rightBox"><div class="rightBoxTop"></div><div class="rightBoxMid" >    
        <h2>Top Tags</h2>    
<ul id="widgetContainer5772b0c14a8a425d81742577e1e4f6f5_5772b0c14a8a425d81742577e1e4f6f5_ulTags">
id widgetContainer is that use you.... mmmm why in widget text i don't have widgetContainer?????

theme is AllTuts and it's in Gallery

very strange!
May 28, 2013 at 2:54 PM
you could try this little trick:
<!-- Begin #colRight -->
  <div id="colRight">
    <div id="topWidget">
    @if (Request.Url.ToString().ToLowerInvariant().Contains("default.aspx") || Request.Url.ToString().ToLowerInvariant().Contains("blog.aspx"))
       <div id="midWidget">
      <div id="bottomWidget">
<!-- End #colRight -->
so: add a BlogEngine Widget Zone, with your widget that should be visible if requested url contain default.aspx, blog.aspx and so on.
Sorry, but I don't know how to convert webform into razor syntax.
May 28, 2013 at 8:01 PM

drago it's a similar solution that i had already used... !!

Thank you anyway :-)