Impossible to show client side validation summary message on form validation failure using the default MS MVC 3 validation?

by martin 15. April 2011 23:05

So Microsoft has a bug in that they do not allow you to show the validation summary message in client side validation mode when you tell it to exclude the property error detail messages in the Html.ValidationSummary(true,"Please enter the required fields below.") way.

I've seen people fix this using jquery validation and unobstructive, but not with the out of the box default MicrosoftMvcValidation.js.

So there were two problems: 

The first was that passing true to ValidationSummary set the replaceValidationSummary parameter in the autogenerated window.mvcClientValidationMetadata.push statement.  What they should have been doing instead is simply not initializing the validationSummaryULElement.  

Ok... this isn't pretty, but it works.  Simply load MicrosoftMvcValidation.js in your page and then execute the code below to dynamically patch the code.

$(function () {    // this function fixes a bug.  It allows the validation summary message to be shown clientside even when the "excludePropertyErrors" bool is set to true in Html.ValidationSummary    
	var old_validate = Sys.Mvc.FormContext.prototype.validate;    
	Sys.Mvc.FormContext.prototype.validate = function () {        
		if (this.replaceValidationSummary == false) {  // only mess with this if it is turned off (MS bug)            
			this.replaceValidationSummary = true// this is for both the debug and non debug versions            
			this._validationSummaryULElement = null;  // this is for the debug version            
			this.$8 = null;  // this is for the non debug version (does the same thing as the line above)        
		}        
		return old_validate.apply(this);   
	}
});

Currently rated 3.0 by 5 people

  • Currently 3/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5

Tags: , ,

ASP.Net | JavaScript

HTML 5 deserves to be called Web 3.0

by martin 20. April 2010 23:48

I have been praising HTML 5 everywhere lately.  I am very impressed despite the fact that they couldn't agree on a single video codec.  Canvas and WebSockets are going to revolutionize what web applications can do, so there is no wondering why Microsoft feels intimidated enough to be the very last major web browser not to support it what-so-ever.  Let's see, FF Chrome Opera and Safari all have it as do the Android and iPhone browsers.  For peat sakes, Google even released two different plugins that give HTML 5 support to IE, so you know it isn't a matter of not being able to do it with all the resources that MS has.  So what is the only other logical reason why they have been holding out?  Politics.  They are probably afraid of what this will do to MS office.  I couldn't even begin to imaging how wonderful Google Apps would be if they only had to write to HTML 5 compliant web browsers.  Also, just as HTML5 has been labeled the "Flash Killer", it probably yields Microsoft's Silverlight a lot less useful too.  Too bad for me and you....  Web 3.0 will have to wait just a bit longer until either Microsoft decides it is ready for it or until the world realizes that IE hasn't been the "best browser" for many years now and finally switches to Chrome.

Click this link to see some really cool HTML 5 Canvas tag examples.

I was amazed to read that the GWT was extended to support WebGL and can now successfully convert the Java version of Quake II to HTML5 and JavaScript.  Amazing!

 

Currently rated 3.0 by 2 people

  • Currently 3/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5

Tags: ,

AJAX | JavaScript

JavaScript to redirect to https

by martin 22. July 2009 21:41

First off, you should never use JavaScript as a security enforcement mechanism, but you can use it within your server's "HTTPS required" error page to automatically (and easily) redirect your viewers to the proper secure page.

So first, configure IIS or Apache to "Require SSL".  This will automatically take all users that attempt to target a non HTTPS url to your servers configured 403 (or 403.4) error page.  Now go edit that error page (my IIS 7 error page was located at C:\inetpub\custerr\en-US\403.htm; for IIS 6 it was C:\WINDOWS\Help\iisHelp\common\403-4.htm) and add something like this:

<script type="text/javascript">

//<![CDATA[

function RedirNonHttps() {

    if (location.href.indexOf("https://") == -1) {

        location.href = location.href.replace("http://", "https://");

    }

}

//]]>

</script>

Then, simply call the RedirNonHttps function on page load :

<body onload="RedirNonHttps();" >

Be the first to rate this post

  • Currently 0/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5

Tags: ,

JavaScript

Local IP Address bug in some JVMs

by martin 21. October 2008 23:47

This guy from Spi Dynamics (now HP) told me how you can get the local IP address in some browser / JVM combinations a few months back.

window.java.net.InetAddress.getLocalHost();

Click here to see if you are at risk.

Inside an applet, you seem to always be able to get the internal ip address using code like :

String strLocalIPAddress = (new Socket(strWebHost, intPort)).getLocalAddress().getHostAddress();

I haven't been able to get this work via javascript. Go to see Lars Kindermann's MyAddress applet to check if you are at risk: http://www.reglos.de/myaddress/MyAddress.html

I also ran across a cool DNS Pinning applet/service that did port scanning. http://www.jumperz.net/index.php?i=2&a=1&b=9

Now add in CIFS / SMB into your dns pinned applet and ? ?  

Be the first to rate this post

  • Currently 0/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5

Tags: , , ,

Java | JavaScript

Update on site rebuild

by martin 27. August 2008 01:26
Update - I just added a page for the PIV and for my open source AJAX World Web Chat Client and web services Server.

Currently rated 3.7 by 3 people

  • Currently 3.666667/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5

Tags: , ,

AJAX | ASP.Net | C# | JavaScript | PIV

Welcome

Please contact me if you have a great idea for a project and need technical expertise in designing, developing, or integrating a custom software solution.

Recent Comments

Comment RSS