Posts

Showing posts from 2009

Only Vertical scroll bar, no horizontal scroll bar – CSS

overflow-x:hidden; oveflow-y:scroll;

ModelState.AddModelError NullReferenceException (ASP.Net MVC Validations)

While trying to add validation errors to the ModelState using the AddModelError method, I was getting “NullReferenceException” run time errors. After doing some research I found that if we follow the AddModelError with SetModelValue method as shown by the highlighted line below, the system doesn’t throw runtime NullReferenceException anymore. ModelState.AddModelError(PropertyName, ErrorMessage); ModelState.SetModelValue(PropertyName,ValueProvider[PropertyName]);

Browser specific CSS style & Firefox, Safari & IE hacks

As different browsers come into existence, it makes the life of web developers living hell, thankfully Microsoft .net enables ASP.Net server controls to specify browser specific styles For example: < asp : Label ID ="Label1" runat ="server" Text ="Browser specific style" ie : Style =" color : Red ; " mozilla : Style ="color:Blue;" style=”color:Yellow;”> asp : Label > The above label will render in blue color on Firefox and in red color on IE & if the browser is other than IE and FF then the label will be displayed in yellow color. References: Programming Microsoft ASP.Net 3.5 http://ryanfarley.com/blog/archive/2008/08/14/more-on-device-filtering-with-asp.net-server-control-properties.aspx http://weblogs.asp.net/johnkatsiotis/archive/2008/08/12/asp-net-browsers-filter.aspx

Caching whole page except a user control in ASP.Net application

Approach 1) As described in the following figure, the page is divided into 4 user controls, 3 of them are cached and 1 of the control that you want to load dynamically is not cached. Gotcha: In this approach we have to make sure that we do not add the output cache directive ( <%@ OutputCache Duration="86400" VaryByParam="none" %>) to the page. User control 1 <%@ OutputCache Duration="86400" VaryByParam="none" %> User control 4 (Not Cached) <%@ OutputCache Duration="86400" VaryByParam="none" %> User control 3 <%@ OutputCache Duration="86400" VaryByParam="none" %> User control 4 <%@ OutputCache Duration="86400" VaryByParam="none" %> Approach 2) In this approach you can use server control and add substitution API to call a static method on the page to get dynamic string that wil

How to use Microsoft Enterprise Logging Application block in Medium Trust level?

1) Medium or less trust level does not allow access to the Windows Event Log (System.Diagnostics.EventLogPermission) 2) In the case where access to the Windows Event log is not allowed, I would recommed we write the Error or Trace logs to a Flat file under the root directory e.g. root\log\Error.log (In medium security the application only has access to the root directory and folders under it) 3) Add a section under the “web.config” file for logginConfiguration as shown below, make sure the requiredPersmission = “false” < section name = " loggingConfiguration " type = " Microsoft.Practices.EnterpriseLibrary.Logging.Configuration.LoggingSettings, Microsoft.Practices.EnterpriseLibrary.Logging, Version=4.1.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35 " requirePermission = " false " /> 4) Add Flat File Listener under the logginConfiguration section Logging Application block allows writing to multiple