Archive

Archive for January, 2009

Dynamiczne podpinanie zdarzeń w jQuery

January 23rd, 2009

Po przeładowaniu strony, zdarzenia w jQuery nie zawsze się podpinają. Trzeba to zrobić tak:

// Podpięcie zdarzeń po postbacku:
var prm = Sys.WebForms.PageRequestManager.getInstance();
prm.add_endRequest(bindEvents);
 
// Po załadowaniu się strony.
$(document).ready(bindEvents);
 
// Podpięcie zdarzeń.
function bindEvents()
{
	// kliknięcie na tabeli:
	$("table#tableElements").click(clickOnTable);
}

Obsłużenie zdarzeń po np. kliknięciu na dynamicznie dodane nowe elementy:

// Ustawiam zdarzenia na tabeli. I wtedy nieważne czy się dodało dynamicznie nowe elementy.
function clickOnTable(event)
{
	var target = $(event.target);
 
	if (target.is('a.lnkEditMenu')) return clickEditMenu(target);
	if (target.is('a.lnkDeleteElement')) return deleteElement(target);
	if (target.is('a.lnkEditElement')) return editNoteElement(target);
};

źródło: part 1, part 2

Development ,

How to back up/convert your VSS data to SVN

January 21st, 2009

Whole process looks very simple: grab VSS, produce text file, run SVN and consume produced file.

  1. Download and install (unpack) vss2svn
  2. Run vss2svn.exe
    vss2svn.exe --vssdir \\vss\repository\path
  3. That will produce
    vss2svn-dumpfile.txt

    file which will be consume by svnadmin

  4. [Optional]: compress and send vss2svn-dumpfile.txt file. I’m using 7-zip:
    "{PathTo7-Zip}\7-Zip\7z.exe" a "%DATE% vss2svn-dumpfile.7z" "vss2svn-dumpfile.txt" -t7z -mx9 -aoa
  5. Run svnadmin, use vss2svn-dumpfile.txt
    "{PathToSVN Server}\VisualSVN Server\bin\svnadmin" load "E:\SVN Repositories\BackupVSS" < "vss2svn-dumpfile.txt"
  6. And thats it.

Whole script might look like this:

E:
CD E:\Vss2Svn\
vss2svn.exe --vssdir \\vss\repository\path
 
:: ### Optional compression, you might do this if you want send file somewhere else ###
"C:\Program Files (x86)\7-Zip\7z.exe" a "%DATE% vss2svn-dumpfile.7z" "vss2svn-dumpfile.txt" -t7z -mx9 -aoa
 
:: ### SVNAdmin ###
"C:\Program Files (x86)\VisualSVN Server\bin\svnadmin" load "E:\SVN Repositories\BackupVSS" < "vss2svn-dumpfile.txt"

Tools , , , ,

HTML encoding in JavaScript

January 15th, 2009

This little function converts HTML characters (for example brackets < >) to entities (like &lt; &gt;).

function escapeHTMLEncode(str)
{
	var div = document.createElement('div');
	var text = document.createTextNode(str);
	div.appendChild(text);
	return div.innerHTML;
}

Source: http://sanzon.wordpress.com

Development ,

Hitting the backbutton in the browser causes the fckeditor to display the HTML tags

January 13th, 2009

Add following code to file: FCKEditor\editor\fckeditor.html

window.onload = function()
{
  // 25-11-2008 Han:  Fixing the issue with the backbutton, when the back/forward button is hit then the html to display is
  // still HTMLEncoded which will cause the control to display html control sequences in the editor.
  // The easiest solution is probably to always htmldecode the value before it is beaing displayed in the editor, this can be done
  // using the statement below.
  // FCK.LinkedField.value=FCKTools.HTMLDecode(FCK.LinkedField.value);
 
  FCK.LinkedField.value=FCKTools.HTMLDecode(FCK.LinkedField.value); // THIS LINE
 
  InitializeAPI(); // existing code line
  .......
}

After adding the code line you will have to make sure that the javascript is downloaded to the client, so in your browser delete the local files ( tools->internet options->delete files).

And then it should all work as expected.

Source: FCKEditor forum

Development , ,

How to call WebService via JavaScript

January 13th, 2009
  1. Get webservice.htc (eg. from here),
  2. Copy it to the same directory as the Web page that uses the behavior. By placing the webservice.htc file in the same directory as your HTML page that calls it, you avoid any DHTML behavior-related cross-domain security issues,
  3. Attach WebService behaviour to an element using the STYLE attribute f.e.:
    <body id="webServiceCaller" STYLE="behavior:url(webservice.htc)"></body>
  4. Establish friendly name for WebService:
    <script language="JavaScript" type="text/javascript">
    function loadService()
    {
    	webServiceCaller.useService("http://address.to.your.service/YourService.wsdl", "MyService");
    }
    </script>
  5. Load service with page load:
    <body id="webServiceCaller" STYLE="behavior:url(webservice.htc)" onload="loadService()">
    //...
    </body>
  6. Create handler for WebService result:
    function handleResult (result)
    {
    	if (!result.error)
    	{
    		alert("Success! Result: " + result.value);
    	}
    	else
    	{
    		alert("Failed! Error: " + result.errorDetail.string);
    	}
    }
  7. Call WebService method:
    • Asynchronous
      function myMethodAsync()
      {
      	callID = webServiceCaller.MyService.callService(handleResult, "MyMethod", "Asynchronous Call");
      }

      result.id should be identical to the integer returned by the myMethodAsync() method.

    • Synchronous
       function myMethodSync()
       {
      	var co = webServiceCaller.createCallOptions();
      	co.funcName = "MyMethod";
      	co.async = false;
      	var oResult = webServiceCaller.echo.callService(co, "Synchronous Call");
      	handleResult (oResult);
       }

      For synchronous call you can use onserviceavailable event f.e. for disable buttons or other controls.

    You don’t have to specify result handler, you can insteed handle the onresult event in webServiceCaller.

  8. Whole code listing:
    <header>
     <script language="JavaScript" type="text/javascript">
     function loadService()
     {
    	webServiceCaller.useService("http://address.to.your.service/YourService.wsdl", "MyService");
     }
     
     function handleResult (result)
     {
    	if (!result.error)
    	{
    		alert("Success! Result: " + result.value);
    	}
    	else
    	{
    		alert("Failed! Error: " + result.errorDetail.string);
    	}
     }
     
     function myMethodAsync()
     {
    	callID = webServiceCaller.MyService.callService(handleResult, "MyMethod", "Asynchronous Call");
     }
     </script>
    </header>
    <body id="webServiceCaller" style="behavior:url(webservice.htc)">
     <button id="callAsynch" onclick="myMethodAsync()">Call Asynchronously</button>
    </body>

Based on: Web Services: Calling Service Methods
About WebServices: MSDN: About the WebService Behavior

Development ,

Problems, tips and tricks in ASP.NET and AJAX

January 12th, 2009
  • SecurityTrimming doesn’t  work with Menu control and when Windows authentication is used. Menu becomes invisible or only root node is visible.

Create root node as

<siteMapNode url=”home.aspx” title=”Home” roles=”*”>.

If it still doesn’t work try to add roles attribute to other siteMapNodes.

  • How to refresh an UpdatePanel using JavaScript?

Use __doPostBack() method in JavaScript code:

function someFunction ()
{
 
__doPostBack('UpdatePanel1', '');
 
// or try this if code above doesn't work:
// __doPostBack('&lt;%= UpdatePanel1.ClientID %&gt;', '');
 
}

Development , , ,

Problem Solved

January 12th, 2009

Error: The specified metadata path is not valid. A valid path must be either an existing directory, an existing file with extension ‘.csdl’, ‘.ssdl’, or ‘.msl’, or a URI that identifies an embedded resource.Source: forums.microsoft.com

ADO.NET Entity Framework

OS: Vista x64

Platform: VS 2008

The catch is that apparently the designers are not supported on 64-bit machines. You should copy two files from %windir%\Microsoft.NET\Framework64\v3.5 to %windir%\Microsoft.NET\Framework\v3.5:

  • Microsoft.Data.Entity.Build.Tasks.dll
  • Microsoft.Data.Entity.targets

then restart Visual Studio and rebuild your solution.

Tools , , ,

Problem solved

January 12th, 2009

Error: The selected file is not a valid solution file.

Platform: VS 2008

Description: When one trying to use VisualSourceSafe 2005 with VisualStudio 2008 one get above error.

Solution:

  • First install Visual Source Safe 2005 Update CTP
  • Next run as administrator the following command: regsvr32 “%programfiles%\Microsoft Visual SourceSafe\tdnamespaceextension.dll”


Source: http://blogs.msdn.com/richardb

Tools , ,