Showing posts with label Ajax. Show all posts
Showing posts with label Ajax. Show all posts

Wednesday, October 12, 2011

Sample ASP.NET Ajax Leaky Abstraction

Below is the work-around for problem on non-working ASP.NET UpdateProgress(with AssociatedUpdatePanelID) when the control(e.g. Button) that causes the post-back is outside of the UpdatePanel. This is the cause of the error:

http://stackoverflow.com/questions/1187953/updateprogessbar-is-not-working-when-setting-associatedupdatepanelid


This is the solution for ASP.NET AJAX leaky abstraction :-)

http://stackoverflow.com/questions/996957/why-does-update-progress-does-not-fire-when-associatedupdatepanelid-is-set


An implementation:

<%@ Page Title="Home Page" Language="C#" MasterPageFile="~/Site.master" AutoEventWireup="true"
    CodeBehind="Default.aspx.cs" Inherits="WebApplication7._Default" %>

<asp:Content ID="HeaderContent" runat="server" ContentPlaceHolderID="HeadContent">
    <script type="text/JavaScript" language="JavaScript">
        function pageLoad() {
            var manager = Sys.WebForms.PageRequestManager.getInstance();
            manager.add_beginRequest(OnBeginRequest);
        }
        function OnBeginRequest(sender, args) {
            var postBackElement = args.get_postBackElement();
            if (postBackElement.id == 'MainContent_Button1') {
                var up = $get('MainContent_UpdateProgress1');
                up.style.display = "block";
            }
        }
    </script>
</asp:Content>
<asp:Content ID="BodyContent" runat="server" ContentPlaceHolderID="MainContent">
    <h2>
        Welcome to ASP.NET!
    </h2>
    <p>
        To learn more about ASP.NET visit <a href="http://www.asp.net" title="ASP.NET Website">
            www.asp.net</a>.
    </p>
    <asp:ScriptManager ID="ScriptManager1" runat="server">
    </asp:ScriptManager>
    <asp:UpdatePanel ID="UpdatePanel1" runat="server">
        <Triggers>
            <asp:AsyncPostBackTrigger ControlID="Button1" />
        </Triggers>
        <ContentTemplate>
            <asp:Label ID="Label1" runat="server" Text="Label"></asp:Label>
        </ContentTemplate>
    </asp:UpdatePanel>
    <asp:Button ID="Button1" runat="server" Text="Button" OnClick="Button1_Click" />
    <asp:UpdateProgress ID="UpdateProgress1" AssociatedUpdatePanelID="UpdatePanel1" runat="server">
        <ProgressTemplate>
            Loading ...</ProgressTemplate>
    </asp:UpdateProgress>
</asp:Content>


This sort of leaky abstraction on ASP.NET of simulating states in an otherwise stateless protocol is making me embrace MVC+jQuery combo even more.

And someday, you won't get any answer on this type of question on forums, as it will be deemed too localized a few years from now. Five years or more, give or take, most developers will be using MVC+jQuery or node.js+jQuery already, and you will hardly find someone able to answer this ASP.NET type of question.

Friday, February 18, 2011

ASP.NET MVC-backed jQuery AJAX ComboBox

Look Ma! No ViewState!

I've ported a PHP-backed jQuery Ajax ComboBox to ASP.NET MVC one. You could download it at http://code.google.com/p/asp-net-mvc-backed-jquery-ajax-combobox/downloads/list


Ignore ASP.NET MVC at your own peril 1


Ignore ASP.NET MVC at your own peril 2

This is another quite debated point. At first sight, ASP.NET MVC seems to be a whole step backwards as far as productivity is concerned. What’s your definition of productivity? Being able to write 10 Web pages a day? I agree that if you take a quantity-based approach to measure productivity, ASP.NET MVC will lose the game with ASP.NET Web Forms. The “productivity” that the server control model guarantees is really hard to beat. But we are used to adding several days of maintenance and post-delivery debug to our counts for a project. This is largely due to the low quality of the code the Web Forms model allows us to write—most of the time.

Low quality is loss of money. The “apparent” speed (oops, productivity) is partly lost due to the extra work of post-delivery debug, optimization, fine-tuning, refactoring, and testing. An initial higher quality of code will take more time to get into production but will save extra work later.

Once you use it, you inevitably find out that ASP.NET MVC is highly productive—much more than Web Forms. Quick code of higher quality. It won’t happen on day 1, though, and it requires awareness and a bit of study. ASP.NET MVC propounds a quality-based approach to productivity.


"How to argue properly"

"Keep your friends close and your friends that can help you debug regexs even closer."

UPDATE: April 16, 2011

I wrote an ASP.NET Helper for jQuery Ajax ComboBox