Browser navigation with AJAX pages

Recently I came to this issue, and after a lot of googling around I found a simple and powerful solution so I thought it would be beneficial for everyone to know about it. It’s called jQuery Address, and you can find it on the page of Asual. Let’s download it now.

My main problem was that I’m hijaxing almost all of my links in my ASP.NET MVC application, and doing this prevented me from using the browser’s back and forth buttons. I could easily live with this, but my designer couldn’t so I had to come up with a solution. I must warn everyone that it was just pushed together in a hassle, and you could almost see the duct tape holding it together, but it works (for now). Continue reading “Browser navigation with AJAX pages”

Advertisements

ASP.NET AJAX Application Services

In this post, we’ll examine the built-in services in ASP.NET AJAX. You call these services in a same way as you’d call any custom web service from script, but there are some differences.

There are three built-in services in ASP.NET AJAX, namely:

  • Authentication service
  • Role service
  • Profile service

To use these services, you must take two steps: first, configure that you’d like to call these services in your web.config file, then call the configured services from script in your pages. Both the configuration and the calling code is different for the three services, so lets get started with authentication.
Continue reading “ASP.NET AJAX Application Services”

Create and Register Client Script

There are three ways of defining a client script on an ASP.NET Web page:

  • Define a script block on your page
  • Use the ClientScriptManager class to dynamically add JavaScript at run time
  • Use the ScriptManager server control to register JavaScript

Now let’s look deeper into the details. The first method of defining scripts is the traditional method. It has nothing to do with ASP.NET, so you can embed your scripts like this into simple HTML pages or PHP as well. You should add a script tag anywhere on your page (the head section is the most preferred) and define your JavaScript there, like this:

<script type=”text/javascript”>

    function myFunc() {

        //do something

    }

</script>

Continue reading “Create and Register Client Script”

Implement Web Forms by using ASP.NET AJAX

Using ASP.NET AJAX provides the following benefits:

  • Improved efficiency, since a massive amount of processing occurs in the browser
  • Familiar UI elements
  • Partial-page rendering
  • Client integration of ASP.NET services, such as authentication, roles, profiles
  • Auto-generated proxy classes for web services called from client script
  • Extendible controls with client functionality
  • Browser compatibility

 
Continue reading “Implement Web Forms by using ASP.NET AJAX”

Calling Web Services from Client Script

Web services can be called from client scripts, such as Javascript too. This is most useful for example if you need to expose a database result set to your javascipt client code. Both XML Web services and WCF services can be called from client script. The steps are essentially the same for both scenarios.

First you must expose your service to be consumable from client script. For a standard XML Web service, add the ScriptServiceAttribute to your .asmx.cs file. If you work from template, you just need to uncomment the line. Your result would look like this:

ScriptService1

To set up a WCF service, you should ensure of the following:

  1. The service must be hosted by a web application within a .svc file. You will need to point to this file later.
  2. You must configure the web application to support service calls from client script.

Continue reading “Calling Web Services from Client Script”

Debugging ASP.NET AJAX

Debugging javascript

Debugging an ASP.NET AJAX application presents its own issues. It is not the classic debugging process, because here, our code is hosted within a browser (in other words, the code is interpreted by another process). So first, we must configure our browser to enable script debugging. This is not a big thing to accomplish, just open Internet Explorer, select tools, Internet Options, and then the Advanced tab. There, you should seek for a checkbox names Disable Script Debugging (Internet Explorer). Clear it, and script debugging is enabled. Clear the other one with the same name and you can debug client script in other browser, too.

There is a little problem yet. You will notice it when you start browsing whatever site you would like. A pop-up window will constantly shows up, and informs you about the found script errors on a given page. This behavior cannot be turned off, so you should only enable script debugging, when you are debugging, otherwise you can debug the whole Internet.

With client-side script debugging enabled, you can set breakpoints in javascript code, read the values of your variables at runtime, etc. If you take a look at your page when doing client-side script debugging, you will see that you are working with the rendered HTML page, so you won’t see any <asp:something> tags, but rendered HTML code. Because HTML is stateless, there would be no point in modifying the variable values when debugging. This is a necessary constraint in client-side script debugging, so be aware of it.

Attach to script

Attaching to a running script is easy. Just use Visual Studio’s (note that Express editions cannot attach to processes) Attach to Process, and select the script you’d like to attach to. You can narrow the available processes considerably if you look only for Script processes (in the Category column).

Continue reading “Debugging ASP.NET AJAX”