Programming is Passion,Software Development is an Adventure- Willy David Jr

Programming is Passion,Software Development is an Adventure- Willy David Jr

July 2008 - Posts

Adding AJAX to ASP.NET 2.0 Websites

This was really my problem wayback I starting learning AJAX. I cannot figure it out on how to add AJAX capability if I already have an existing website. One solution I remember at that time is I created an AJAX enabled website and transfer all my work there. Quite a tedious task, but that's what I really did! Anyway, as a benefits for others so that they will learn from my lesson, you don't really need to transfer your work, all you need is a bit of referencing, and additional configuration to your web.config file. And that's it, you can now use your UpdatePanel independently per page.

Here how it goes:

1.) Add a reference of AjaxControlToolkit.dll on your website. After that, you will see that your BIN folder is updated.

2.) Next, add <controls> tag under your <system.web> node. Here is the code:

<controls>
       <add tagPrefix="asp" namespace="System.Web.UI" assembly="System.Web.Extensions, Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"/>
</controls>

3.) That's it. But if you are getting an error and if you still experience a postback on your page. Just add this addition tag/node under your <system.web>


<httpHandlers>
      <remove verb="*" path="*.asmx"/>
      <add verb="*" path="*.asmx" validate="false" type="System.Web.Script.Services.ScriptHandlerFactory, System.Web.Extensions, Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"/>
      <add verb="*" path="*_AppService.axd" validate="false" type="System.Web.Script.Services.ScriptHandlerFactory, System.Web.Extensions, Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"/>
      <add verb="GET,HEAD" path="ScriptResource.axd" type="System.Web.Handlers.ScriptResourceHandler, System.Web.Extensions, Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" validate="false"/>
    </httpHandlers>
    <httpModules>
      <add name="ScriptModule" type="System.Web.Handlers.ScriptModule, System.Web.Extensions, Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"/>
</httpModules>

 

That's it, your website must be fully working and functional using the power of AJAX!

// Willy David Jr

 

Problem on Postback when using Modal Pop-up Window

I was doing an online job application this week when I encounter this problem. I can create Modal pop-up window using BLOCKED SCRIPT

myLinkButton.Attributes.Add("onclick", "BLOCKED SCRIPTwindow.showModalDialog('http://" + myUrl + "')");

Everything works fine, because the user cannot navigate to any other page unless he/she closes the window first. Until one thing, when he presses or click the Submit button of the modal popup, another window opens, the same window and URL I used on my modal pop-up. The problem was, you cannot make a postback inside a modal pop-up window. It will just trigger the same problem as I does.

Anyhow, we are already on information age, and I found one very good solution to this, create a new web form page, put a frame control on the page, and link that frame control to your modal pop-up window. Here is the code for my FrameApplicationForm.aspx:

 

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="FrameApplicationForm.aspx.cs" Inherits="Portals_0_Skins_GurangoSkin_MainUserControls_FrameApplicationForm" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html>
<HEAD>
<TITLE>Online JOB Application</TITLE>
</HEAD>
<frameset rows="100%">
    <frame name="mainframe" src="ApplicationForm.aspx" bordercolor="0" title="Navigation bar">    <--- Link your modal pop-up window here
</frameset>
</html>

 

The on the javascript declaration, use the url of this frame application form page:

string myURLforFrameApplicationPage= "~/FrameApplicationForm.aspx";

myLinkButton.Attributes.Add("onclick", "javascript : window.showModalDialog('http://" + myURLforFrameApplicationPage+ "')");

 

Now everything works fine, and I can now proceed to my next task! :)

 

// Willy David Jr