onsdag den 25. februar 2015

Searching for DOM elements


From the site http://javascript.info/tutorial/searching-elements-dom we get this summary
There are 5 main ways of querying DOM:
  1. getElementById
  2. getElementsByTagName
  3. getElementsByName
  4. getElementsByClassName (except IE<9)
  5. querySelector (except IE<8 and IE8 in compat mode)
All of them can search inside any other element. All of them excepts the last one return live collections.


XPath is kind-of supported in most browsers, but very rarely used.

tirsdag den 24. februar 2015

Simple JavaScript callback to asp.net page server method (webservice) - part 2


Simple JavaScript callback to asp.net page server method (webservice)
- easy as client JavaScript method (except call should be asyncrone - se later)
- manage type as JavaScript (don't think of converting to json or xml)

Pp_JavaScriptCodeBehindOgPageMethods.ppt
example: JavaScriptValideringSolution_20140331.zip
Another example with javascript calling server with PageMethod for data:
JavaScriptCallPageWebmethodSolution.zip


If you want to make easy acces to methods on server from javascript in ASP.NET environment, you just can use a ASPX Webform for hosting af service on the page.
You just need to place a ScriptManager to control access in a ASPX form objet - both with runat sever properties. Rest og the file could be pure Html and javascript.
Remember to eable page methods.

<form id="form1" runat="server">
          <asp:ScriptManager ID="ScriptManager1" EnablePageMethods="True"
                    EnablePartialRendering="true" runat="server"/>
 </form>

Place the server method on the codebehind c# file with atribute for method like this
In this example it just call another (wcf soap) service to do the job.
In the ASPX page C# page

        [System.Web.Services.WebMethod]
        public static PostWcfService.PostdistriktDTO[]  GetAllPost(int fromPost, int toPost)
        {
            PostWcfService.PostWcfServiceClient service =
                new PostWcfService.PostWcfServiceClient();
            return service.GetAllePostdistrikterFraTil__PostnrOrder(fromPost, toPost);
        }

In the JavaScript the method is called like this

    PageMethods.GetAllPost(5000, 5200, onSucessGetAllPost, onerrorGetAllPost);

First the parameter to the webmethod followed by at callback method to pass the result and last a callback method i the page method fails.

function onSucessGetAllPost(result)
{
       // result is an Javascript Array object containing Postdistrict objects
       // and is ready to use -  fx running through by for-loop and displayd in UI
}
}
function onerrorGetAllPost(result) {
      // to do for errorhandling
}

Normally you have a problem calling webmethod on another site,
With this solution we solved the problem with the page method. The page method will act like a proxy/broker for the external service.

You can find a soluton with the example here - also getting data with WebClient for JSON, XML, HTML and TEXT...
Week09_SolutionJavaScriptPart02_WithWebClientData_20150224.zip

An a expanded example with som coverting text from WebClient in JSON, XML and HTML to javascript objects.
Week09_SolutionJavaScriptPart03_WithWebClientDataConverted_20150224.zip




fredag den 20. februar 2015

Simple JavaScript callback to asp.net page server method


Simple JavaScript callback to asp.net page server method (webservice)
- easy as client JavaScript method
- manage type as JavaScript (don't think of converting to json or xml)

Pp_JavaScriptCodeBehindOgPageMethods.ppt
Fra undervisningen: JavaScriptValideringSolution_20140331.zip
Eksempel med hentning af data ved  javascript der kalder PageMethod for data:
JavaScriptCallPageWebmethodSolution.zip

Asp.net materiale fra tidligere kursus (5 ects)

Asp.net materiale fra tidligere kursus (5 ects)
Ugeplaner
Eksempler_og_noter
Opgaver

JavaScript materiale fra tidligere kursus på 12 lektioner

Tutorials til javascript


Tutorials til javascript

Beginning JavaScript Tutorials
http://www.pageresource.com/jscript/index.html

JavaScript Tutorial
http://www.w3schools.com/js/default.asp

JavaScript Kit Advanced JavaScript Tutorials
http://www.javascriptkit.com/javatutors/

JavaScript - MDC
http://developer.mozilla.org/en/docs/JavaScript


References
JavaScript Kit- JavaScript Reference
http://www.javascriptkit.com/jsref/index.shtml

JavaScript Core Guide 1.5
http://www.webreference.com/javascript/reference/core_ref/

JavaScript FAQ
http://www.javascripter.net/faq/index.htm


onsdag den 11. februar 2015

Start på web blog

Blog oprettet for brug på datamatikeruddannelsen ved EAL inden for fagområdet udvikling til web udvikling

Det er tanken at studerende er med til at bruge denne blog, herunder som forfattere (henvend dig til Bjørk Boye Busch med en gmail adresse for rettighed som forfatter).

Du finder også materiale på min egen blog http://bjørks.blogspot.dk/