Dusan Czupek's blog

Blog related .NET & web development

Recent posts

Tags

Categories

Navigation

Pages

    Archive

    Blogroll

      Disclaimer

      The opinions expressed herein are my own personal opinions and do not represent my employer's view in anyway.

      Request.UrlReferrer Is Null In IE 6.0 when location.href(Javascript) is used to redirect

      Microsoft announced fix will be from IE9. Until you can avoid problems with following code:

      function navigateWithReferrer(url)
      {
        var fakeLink = document.createElement ("a");
        if (typeof(fakeLink.click) == 'undefined')
          location.href = url; // sends referrer in FF, not in IE
        else
        {
          fakeLink.href = url;
          document.body.appendChild(fakeLink);
          fakeLink.click(); // click() method defined in IE only
        }
      }

      The trick is that, although location.href navigation (and window.navigate() too) doesn't send a referrer, the IE-only click() method on a hyperlink will send a referrer. So if you create a hyperlink, set its href, and then click() it with script, you'll get the referrer you want.

      Unfortunately the click() method isn't supported on hyperlinks in some versions of Firefox, so you need to check for its presence and use location.href if it's not there. Since location.href sends a referrer on firefox, it works fine.
      Posted: Aug 05 2009, 12:57 by dczupek | Comments (27) RSS comment feed |
      • Currently 1/5 Stars.
      • 1
      • 2
      • 3
      • 4
      • 5
      Filed under: dotNet

      ReSharper for Visual Studio 2010 (Preview)

      Finally JetBrains launched ReSharper v.5.0 for VS2010 after a month delay against previous announce.

      Installation it self should be a bit tricky. First of all download a nightly build of ReSharper from

      ReSharper EAP - ReSharper for Visual Studio 2010 (Preview). The download links are located at the very end of the page.

      1) Before you click on downloaded .vsix file I highly recommend to click on "Load extensions from my local application data folder" in Tools/Options, Extension Manager menu.

      2) Close all your VS2010 instances

      3) After that click on downloaded .vsix file, following installation dialog.

      4) Start VS2010 and open Tools | Extensions Manager menu and confirm that ReSharper is there

      image

      5) Maybe you will meet with registration of evaluation period during VS2010 start up. Basically evaluation period should start automatically, if not use following credentials:  (this will provide you a temporary license till 07/23/2009). I heard that keys from ReSharper 4.5 are working as well.

      User Name: VS2010Beta1
      License Key: 0-dY16Cav/tdLePfqRzD2kp37wt2HXosbp

       

      Check JetBrains Resharper EAP VS2010 regularly for updates.

      Posted: Jul 12 2009, 17:47 by dczupek | Comments (7) RSS comment feed |
      • Currently 0/5 Stars.
      • 1
      • 2
      • 3
      • 4
      • 5
      Filed under: dotNet

      Model View Presenter (MVP) Pattern

      Model-View-Presenter is a user interface design pattern engineered to facilitate automated unit testing and improve the separation of concerns in presentation logic.

      The Model is an interface defining the data to be displayed or otherwise acted upon in the user interface.

      The View is an interface that displays data (the Model) and routes user commands to the Presenter to act upon that data.

      The Presenter acts upon the Model and the View. It retrieves data from repositories, persists it, manipulates it, and determines how it will be displayed in the View.

      The degree of logic permitted in the View varies among different implementations.

      At one extreme, the View is entirely passive, forwarding all interaction operations to the Presenter. In this formulation, when a user triggers an event method of the View, it does nothing but invoke a method of the Presenter which has no parameters and no return value. The Presenter then retrieves data from the View through methods defined by the View interface. Finally, the Presenter then operates on the Model and updates the View with the results of the operation.

      Other versions of Model-View-Presenter allow some latitude with respect to which class handles a particular interaction, event, or command. This is often more suitable for web-based architectures, where the View, which executes on a client's browser, may be the best place to handle a particular interaction or command.

      From a layering point of view, the Presenter class might be considered as belonging to the application layer in a multilayered architectured object-oriented system with common layers but it can also be seen as a Presenter layer of its own between the Application layer and the User Interface layer.

       

      Sample of MVP implementation in few steps:

      1) create an interface (later in the topic will be note like view-interface ) with properties  which will contain values from webpage/form.

      public interface IDataView {
      string FirstName { get; }
      string LastName { get; }
      string Status { set; get; } }

      2) make webpage/form to implement this interface

      public partial class MyPage : System.Web.UI.Page,IDataView

       

      3) implement interface members and map them to webpage/form entries (such labels, textboxes, etc.)

      public string FirstName { get { return this.tbFirstName.Text; } }
      public string LastName { get { return this.tbLastName.Text; } }
      public string Status { set { this.lblStatus.Text = value; }
      get { return this.lblStatus.Text; } }

       

      4) create new class for presenter

      public class DataPresenter { }

       

      5) declare a variable of view-interface type (created at point 1), variable value will be initialized through constructor

      public class DataPresenter
      {
      private IDataView _view;
      }

       

      6) create/extend constructor with input parameter of view-interface type

      public class DataPresenter
      {
      private IDataView _view;
      public DataPresenter(IDataView view) { _view = view; }
      }

       

      7) create public method(s) for manipulate with view

      public class DataPresenter
      {
      private IDataView _view;
      public DataPresenter(IDataView view) { _view = view; }
      public void SaveData() {
      _view.Status = string.Format("FirstName={0}; LastName={1}",
      _view.FirstName, _view.LastName);
      }
      }

       

      8) in webpage/form create an instance of the presenter, constructor requires input value of view-interface type. Because the webpage/form already implements an view-interface, input value for constructor will be this.

      private DataPresenter _presenter;

      protected void Page_Load(object sender, EventArgs e)
      {
      _presenter = new DataPresenter(this);
      }

       

      9) now you can calling presenter’s method(s) from the events etc. If the presenter method change view’s data you’ll get back updated data automatically based on mapping from point 3.

      protected void Page_Load(object sender, EventArgs e)
      {
      _presenter = new DataPresenter(this);
      btnSave.Click += delegate { _presenter.SaveData(); };
      }

       

      In my sample I called the SaveData method on  _presenter presenter.



      Shout it
      DotNetKicks Image
      Posted: Jun 30 2009, 20:56 by dczupek | Comments (9) RSS comment feed |
      • Currently 4.333333/5 Stars.
      • 1
      • 2
      • 3
      • 4
      • 5
      Filed under: dotNet

      Speed up ASP.NET page/control loading

      Often you find yourself waiting after you made changes in code behind. Delay during first page load has to do with code compilation. With simple modification of web.config you can speed up this process a bit. Main issue is that ASP.NET engine by default compiles all files in folder where you page is place. But you can tell to engine that you are interested only current page and it is related controls/components etc. Do simple change:

      Under <configuration><system.web> you can find <compile> element if it does not exists create it. In <compilation> element specify attribute batch with value false.

      Changed part of your web.config should looks like:

      <compilation batch="false">


      Shout it
      Posted: May 20 2009, 08:30 by dczupek | Comments (14) RSS comment feed |
      • Currently 0/5 Stars.
      • 1
      • 2
      • 3
      • 4
      • 5
      Filed under: dotNet