Wednesday, June 2, 2010

Without Postback with disable your browser Javascript

Postback is very heavy code to load (viewstate,etc).
such as you want to get rid of this from your form .


So the solution is you can use AJAX.. to handle all this postback to make your page still dynamic or more responsive that before.

But how about if the client browser disable their javascript..
Your page will be static.

so you need to consider this as well.

So the big picture of this solution is to put ajax as common.
but on the event onclick or href.. you can't just call that function to call an ajax.

for example
href="javascript:CallPostbackFunction();"

you need to change this to
href="/page/ajax/somePage.aspx" class="AjaxCall"

then.. in you can check .. if the browser is enabled the javascript..
then you can call your ajax function.

If the javascript is disabled from your browser then you still can load to the proper page. instead of just do nothing.

//check if browser enabled their javascript
jQuery(document).ready(function() {
//perform init and replace to an proper javascript
var ajaxCalls = $('#ajaxCall');
ajaxCalls.unbind('click', this.addClick);
ajaxCalls.bind('click', this.addClick);
});


Here a good reference for Object Oriented Programming in Javascript
http://devedge-temp.mozilla.org/viewsource/2001/oop-javascript/

Sunday, March 28, 2010

response.d in .net 3.5 JSON

Migrate Json .Net 2.0 to .Net 3.5

Here need to be note...
================
response.d

While I wish this unexpected change had been more clearly announced, it’s a good one. Here’s how Dave Reed explained it to me:

{"d": 1 }



Is not a valid JavaScript statement, where as this:



[1]



Is.



So the wrapping of the "d" parameter prevents direct execution of the string as script. No Object or Array constructor worries.

[] is JavaScript’s array literal notation, allowing you to instantiate an array without explicitly calling a constructor. To expand on Dave’s explanation, simply consider this code:


=====================
make sure you change web.config to use ScriptService of v 3.5 in HttpHandlers

add verb="*" path="*.asmx" validate="false" type="System.Web.Script.Services.ScriptHandlerFactory, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"

Monday, August 3, 2009

Jquery AJAX impacted on document.write

just find a solution, when you use jquery ajax, and there is document.write after that, it will clear all your content..

all u need to do is create a span, where you want to write that content. then.. overwrite document.write function to write into that span instead doing document.write..

here is the sample

span id="test" /span
script document.write = function(text){ jQuery('#test').append(text) }
/script


=D
Here is the reference
http://javascript.about.com/library/blwrite.htm


--------
Huh.. but this still have a problem.. in IE.. if you overwrite into different holder.

so the best solution at this moment is using iframe...

Sunday, May 10, 2009

Change culture without changing deployment Server

Add globalization tag inside System.web tag in Web.Config

globalization requestEncoding="utf-8" responseEncoding="utf-8" culture="en-AU"

Wednesday, April 1, 2009

1st NHibernate.LINQ Limitation

Just found Nhibernate Linq limitation.

It can't translate toLower() on string but luckily, it has compare in case sensitive.

it throws weird error if you use this.
q = q.Where(c => c.firstName.Contains(flter) || c.lastName.Contains(flter) || c.email.Contains(flter));

says
----
Index was out of range. Must be non-negative and less than the size of the collection.
Parameter name: index
----

Monday, March 2, 2009

Restricting Text box (Multiline) using Javascript

//Restrict Length
function restrictLength(e,ctl,maxLength)
{
var evt = e ? e : window.event;

//check the length for copy paste
if (ctl.value.length >= maxLength)
{
//only character
if (e.keyCode == 0)
{
return false;
}
}
return true;
}
-- don't for get to called using (RETURN)
javascript:return restrictLength(event,this,10);

Sending Email from HTML

I decide to use File rather then web request coz some server are restricted to loopback.

///
/// Get Email Body from file
///

///
public static string GetEmailBodyFromFile(string filePath)
{
string emailMasterBody = "";

Encoding encode = System.Text.Encoding.GetEncoding("utf-8");
using (System.IO.StreamReader objReader = new StreamReader(filePath, encode))
{
emailMasterBody = objReader.ReadToEnd();
}

return emailMasterBody;
}