Jan 29, 2013

Proper referencing Master page props from custom control

Proper referencing Master page props from custom control


ASPX Page has Master page declared.
In Master page there is property IsHistory.
Page has custom control.
Custom control has to get access to IsHistory prop of Master.
Possible solutions:

  1. Create interface that describes GetIsHistory and implement it on MasterPage. Then from custom control cast Page.Master to interface and obtain prop value
  2. Alternatively and more object approached:

MasterPage.Init
IsHistory = true;

Page.aspx
<%@ MasterType TypeName="SiteMaster" %>
protected void Page_Init(object sender, EventArgs e)
    {
        uc1.IsHistory = Master.IsHistory;
    }
CustomControl.ascx
public bool IsHistory { get; set; }
<h2><%:IsHistory.ToString()%></h2>

Jan 10, 2013

JQuery / JavaScript code test with markup

When developing Javascript / JQuery code in early phase it tends to be tricky to easily and quickly do some testing.
For experienced in Javascript it is enough FireBug-like plugins in modern browser but in complex projects it can be cumbersome.
Hence some online solutions exist.

http://jsfiddle.net/

http://jsbin.com/

They are quite self-explanatory in purpose.
I can't see how to use them in context of existing complex ASP.NET web forms pages in my website.

Just a quick refresher for a few tricks when using browser developer kits for JQuery testing.

1. Firebug
    Open website. Open Firebug window (F12). Select Script tab.
   You need to define some breakpoint in your markup inside some JQuery code. 
   I'm not sure sometimes you need to reload your website (Ctrl+F5) in order to make breakpoint active.
  Do action on your website to make Firebug "fire" your new breakpoint.
 At this moment you are ready to test your JQuery expression in Console tab of Firebug.

2. Visual Studio + Internet Explorer
  From VS 2010 its possible to debug Javascript code.
  There is only one catch. Make sure when you first start IE browser session to delete all your History and cookie.
  This way you make sure that browser loads latest version of your JS file.
  If not you will see in VS your JS file with [dynamic] suffix. This is NOT OK!
  It means that VS found cached version of your JS file and is using it to debug.