1
votes

I have a CMS I built using Classic ASP with VBscript.

I'd like to convert the registration page to ASPX and make it work ASYNC (AJAX?) so that a person can change one field and that field auto-updates the database but not the whole page.

Optimally, I can send Session variables to that page from my .ASP but it is not necessary! Important. I don't want to choose the wrong framework just in order to keep my session vars! I am happy to manually save a cookie to the user's machine (or even use a querystring) so that when they pull up the ASPX registration page, it knows who it is talking to. Session vars depend on cookies anyway so no biggy.

Oh! Another factor: It would be great if I could utilize as much of my existing Classic ASP code on that page as possible. Which is a plus on the side of MVC? And... is it MVC where I could do something like the following:

<asp:ScriptManager id... runat="server></asp:ScriptManager>
Use <UpdatePanel ... id... runat="server"> control.
    Async code goes here
    <ContentTemplate>

    </ContentTemplate>
</asp:UpdatePanel>  

OK... so do you recommend WebForms, MVC, or Web Pages? I'm using Visual Studio 2012.

Thanks for the advice!

1

1 Answers

1
votes

Since you want to use server controls, like <asp:ScriptManager> and <asp:UpdatePanel> that knocks ASP.NET MVC out of the running.

I would use ASP.NET WebForms and since you want to update just a portion of the page, then an AJAX call to the server is definitely the way to go. You can use the UpdatePanel, but that does a partial post back to the server, but it appears to the user that just a single piece or pieces of the page were updated.

My recommendation is to use ASP.NET AJAX Page Methods, for the following reasons:

  • You want to use an AJAX call to the server; jQuery can easily call a page method
  • You want it to only update a portion of the page, page methods just return data and then the client can update only what it needs to without a post back to the server at all

Here is an example of using an ASP.NET AJAX Page Method:

Markup:

<asp:Label id="Label1` runat="server" CssClass="TheLabel" />
<asp:Button id="Button1` runat="server" CssClass="TheButton" Text="Update Label" />

<script type="text/javascript">
    $(document).ready(function() {
        $('.TheButton').click(function() {
            $.ajax({
                type: "POST",
                url: "PageName.aspx/GetDateTime",
                data: "{}",
                contentType: "application/json; charset=utf-8",
                dataType: "json",
                success: function(result) {
                    $('.TheLabel').text(result.d);
                }
            });

            // Stop button from posting back to the server
            return false;
        });
    });
</script>

Code-behind:

[WebMethod]
public static string GetDateTime()
{
    return DateTime.Now.ToString();
}

Note: The ASP.NET AJAX Page Method must be static, because it is not a page instance, thus does not participate in the page life-cycle, nor does it have access to any of the page controls. It is merely there as an async endpoint on the server to get data and return it to the calling client.