Tuesday, July 10, 2012

ASP.net Client side validation textbox highlight not working

If you are wondering why your text boxes are not highlighted(red border) when your client validations is on there is a validation message but no red border besides everything looks perfect.
I am not going into detail but your validation(highlighting of border) depends on the CSS class(s) called


.input-validation-error
{
      border: 1px solid #ff0000;
      background-color: #ffeeee;
}

Like me tell you if you are expecting this should automagically work then you are wrong. The CSS class that comes with MVC 3 has a bug in it. 
This CSS class will take no effect because the following with take precedence and override this class.

input[type="text"], input[type="password"]
{
      border: 1px solid #c9d7e1;
      padding: 2px;
      font-size: 1.2em;
      color: #444;
      width: 200px;

     
}
Due to this you can see in View Source that the textbox or other html controls has this CSS class in it but has not effect(no red border)

Now if you want to do a quick fix there are two possibilities.
  1. Create another class like this

    input[type="text"].input-validation-error
    {
          border: thick solid #ff0000;
          background-color: #FFC0CB;
    }
     
  2. Or use the !important keyword to add value to your validation class, like this.
    .input-validation-error
    {
          border: 1px solid #ff0000!important;
          background-color: #ffeeee;
    }

Save your CSS file and rerun the app. Now upon validation you should see a red border around your textbox.
Again the perquisite of this article is if everything works on client validation except red border.
If you still didn't see then your client side validation is not working. That's beyond the scope of this article.

Thursday, May 31, 2012

How to Turn on WCF Tracing in 2 steps


There are two steps to turn on WCF tracing.
First is to add a source as shown below inside 'Configuration' element

<system.diagnostics>
    <trace autoflush="true" />
    <sources>
      <source name="System.ServiceModel.MessageLogging">
        <listeners>
          <add
          name="messages"
          type="System.Diagnostics.XmlWriterTraceListener"
          initializeData="Messages.svclog" />
        listeners>
      source>
    sources>
  system.diagnostics>
 

And second is to put the following inside the 'System.ServiceModel' element to start tracing.


<diagnostics>
      <messageLogging
      logEntireMessage="true"
      logMalformedMessages="true"
      logMessagesAtServiceLevel="true"
      logMessagesAtTransportLevel="false"
      maxMessagesToLog="0x7fffffff"
      maxSizeOfMessageToLog="0x7fffffff"/>
diagnostics>

After that your messages will be logged into a file called Messages.svclog.