Archive for the ‘Javascript’ Category
jQuery and asp.net validation controls
Posted on April 11th, 2009 • Filed under Javascript, asp.net • 1 Comment
Just found a nice tip to check with jQuery if all built-in asp.net validation controls on a form are valid.
As an asp.net developer and jQuery advocate I know I’m going to find this tip very useful
http://devoma.com/post/JQuery-and-ASPNET-validators.aspx
ASP.NET Event Validation and “Invalid Callback Or Postback Argument”
Posted on February 5th, 2009 • Filed under Javascript, asp.net • No Comments
I was getting this and pulling my hair out.
My button (server-side) was pumping out a bit of javascript
Page.ClientScript.RegisterStartupScript(GetType(String),
"loginunsuccessful", "<script type=""text/javascript"">
alert('Login unsuccessful – please try again');</script>")
And this kept causing the error.
I tried using the prescribed fix: ClientScript.RegisterForEventValidation(mycontrol.uniqueid) in the prerender. Still got the error.
Here’s how I fixed it. RegisterStartupScript does the job of running at startup by emiting the js right at the foot of the page. I wrapped my JS in jQuery’s own onload code.
Page.ClientScript. RegisterStartupScript(GetType(String),
"loginunsuccessful", "<script type=""text/javascript"">
$(document).ready(function(){alert('Login unsuccessful – please try again');});
</script>")
Still the same error, I then changed to using Page.ClientScript.RegisterClientScriptBlock, which emits the JS in the midst of the html and hey presto no errors. This is without using the RegisterForEventValidation I’d like to add.
Final code:
Page.ClientScript.RegisterClientScriptBlock(GetType(String),
"loginunsuccessful", "<script type=""text/javascript"">
$(document).ready(function(){BlockAlert('Login unsuccessful – please try again');});
</script>")
Simple to fix when you know how.
Use jQuery to replace <body onunload="GUnload()">
Posted on January 26th, 2009 • Filed under Javascript • 7 Comments
When using Google maps it’s important to use GUnload on the page’s unload event. Fine when you can access the body tag directly…. But if you have the Google map functionality wrapped inside an ascx you need a different approach.
After a big of digging I found how to use jQuery to “catch” the unload event. In case anyone else needs it:
$(window).unload( function () { GUnload(); } );
Microsoft adopt jQuery
Posted on October 1st, 2008 • Filed under Javascript • No Comments
I’ve been using jQuery for ages and I love it. Finally a very easy, crossbrowser, method to target any element or group of elements on the page.
Plus it has some very straightforward and powerful ajax features built in.
I did look at the whole ajax.net thing a while back and it was way too bloated for me to give it a serious look.
I’ve just heard the Microsoft have woken up to jQuery too. In future versions of Visual Studio jQuery intellisense wil be built it. Thanks Microsoft!