tags:

views:

73

answers:

1

I have an jQuery accordion for a form on an internal company website. They seriously want to stick with their ASP.net technology (I know I'd bark at them if an intern could do that reasonably).

Project description: Creating a basic CRM form

The first slide of the accordion has their basic input for recording contact information which will include a client we already have recorded. If the contact isn't already in the database and they try to use it, the accordion will move to the next slide and allow the person to fill out a form to record a new client. After that I compare the names to the database again, and show the user the similar names in a third accordion IF and ONLY IF results exist. (I know, redundant, but I want to save myself some duplicates, these are civil engineers they just put in what works as long as its not a bridge calculation)

Actual Problem: ASP.net codebehind takes care of the datasearching and displaying (for now) and jQuery/Javascript/HTML moves the accordion around. Since I only want the accordion to open the last slide if there are results - how do I get enough information from the serverside check of the database to do accordion movements conditionally, while still avoiding full postbacks and refreshes?

Also, I realize this is a little more cosmetic, but right now I do fadeins/fadeouts with jquery - I don't want this to look like jerky 1995 webpage loading with lots of refreshes. So keeping that to a minimum would be more than fantastic.

client.aspx (some of the javascript)

function pageLoad() {
        $("#dymslide").hide();
        var active = $("#accordion").accordion("option", "active");
        if (active = 2) {
            $("#dymslide").show(750);
        }
    }
    $(document).ready(function () {
        $("#ncfslide").hide();
        $("#dymslide").hide();
        $("#accordion").accordion({
            autoHeight: false,
            navigation: true,
            collapsible: true
        });
        $("#saveButton").click(function () {
            $("#dymslide").bind('load', function () {
                $("#Label2").bind('load', function () {
                    var isVisible = $("#Label2")[0].style.display == "block";
                    if (isVisible) {
                        $("#accordion").accordion("activate", 2);
                    }
                });
            });
        });
    });

client.aspx

<center>
                <p>
                    <br />
                    <asp:Label ID="tf" runat="server"></asp:Label>
                    <asp:Button ID="saveButton" runat="server" Text="Save Contact"/>
                    &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
                    <asp:Button ID="cancelButton" runat="server" Text="Cancel" />
                </p>
            </center>
        </div>
    </div>
    <h3>
        <a href="#dym" name="dym">Did you mean?</a>
    </h3>
    <div>
        <div id="dymslide">
            <asp:UpdatePanel ID="up" runat="server">
                <Triggers>
                    <asp:AsyncPostBackTrigger ControlID="saveButton" EventName="Click" />
                </Triggers>
                <ContentTemplate>
                    <p>
                        <asp:Label ID="Label2" runat="server"></asp:Label>
                    </p>
                </ContentTemplate>
            </asp:UpdatePanel>
        </div>
    </div>

client.aspx.vb

Protected Sub saveButton_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles saveButton.Click
    If LikeNames(fNameValue.Text, lNameValue.Text) Then
        Label2.Style("display") = "block"
    Else
        Label2.Attributes.Add("display", "none")

    End If

End Sub

And yes I know - I won't be displaying results in a simple label eventually but as I haven't even gotten these basic things working I don't think I have to worry about it quite yet.

+2  A: 

I would use jQuery.ajax() to call a ASP.Net Webservice and update the form. This webservice might return JSON for example.

Also I would remove the UpdatePanel and trigger. Personally I've found these to usually be more trouble then they're worth. Stick with the direct jQuery.ajax() type calls.

Not sure if you've done much ASP.Net/JQuery but here is a good tutorial to start with.

PS.

  1. I'm not sure the accordian is the right widget for this. Does it feel right to you? Accordians are usually used for collapsible menus, not workflow ( which seems like what you're doing ). I would use a series of forms for that.

  2. Here is an example of a jQuery Wizard. You don't have to use that plugin, but I wanted to show the general concept. Each step in the wizard does not have to be a new page. You can use AJAX to update the current step while staying on the same page.

kervin
I'm actually learning ASP and jQuery on the fly (I'm normally a diehard open-source but can't pick your tools as an intern). Can I guess that with using jQuery.ajax() I can still update pieces of the page using some of the serverside results, while still not refreshing the entire page?
jphenow
Answer to your PS. series of forms as in new pages? The only reason I'd like to avoid that is because a chunk of this will happen so often that I don't want new pages/forms, it will also allow the user to return to the original task (reporting a contact with client) quickly feeling like they never sidetracked
jphenow
Oh yes, you definitely can. After using the Webform approach for a while now, I believe that the jQuery AJAX approach is best. You can use any of the jQuery.ajax() or jQuery.get() examples you find on the web. It's not ASP.Net specific. Though the tutorial in my answer should have some good examples. As a bonus, jQuery would work the same if you use it with PHP or your platform of choice.
kervin
about the pages. They don't have to be *new* pages, they can be a sequence divs updated on a single page using jQuery/AJAX. You would track the current step in the session scope in the code-behind.
kervin
Good I'm glad to hear you say I can use it with PHP. Honestly after this internship I really want to pursue web-application development but I think ASP is POS. I've worked a little with PHP and simply think its better in almost every way. That example you gave me is fantastic! Thank you very much. How would you recommend I not do accordion, while also avoiding refreshes? I really want this form to feel connected enough that they aren't loading and reloading pages a bunch ( I know thats the convention of AJAX, but accordion just looked good enough when i saw it)
jphenow
Hmm interesting I could do that. And I suppose they don't really need to be accordions - this would probably also help remedy the problem I'm currently having. I'll give that a look. I think I became caught up in avoiding the "next"/"previous" method of some of the forms on websites I despise.
jphenow
This is fantastic, this is probably the most helpful post I've had on here in a while. Thanks a lot.
jphenow
I see. For *workflow* type processes, it's hard to escape next/previous. The reason it's done that way is because users can get confused as to what *step* they're at. Try to give ASP.Net a chance for now. I worked with PHP and others for years and ended up with ASP.Net. For large applications the static / strongly typed nature of .Net really helps.
kervin
you're very welcome! glad I could help.
kervin
Good points on the large application of asp and strong type - I don't like loose typed as much usually. It seems like ASP can be such a hog though. I won't claim to know for sure what I want though - as you saw I'm pretty much a self proclaimed n00b. All I did before was go crazy with Wordpress until this internship so I'll know what I like in a few years maybe.
jphenow