Products

Solutions

Resources

Partners

Community

Blog

About

QA

Ideas Test

New Community Website

Ordinarily, you'd be at the right spot, but we've recently launched a brand new community website... For the community, by the community.

Yay... Take Me to the Community!

Welcome to the DNN Community Forums, your preferred source of online community support for all things related to DNN.
In order to participate you must be a registered DNNizen

HomeHomeDevelopment and...Development and...Building ExtensionsBuilding ExtensionsModulesModulesHow to fire a script after an asynchronous postback?How to fire a script after an asynchronous postback?
Previous
 
Next
New Post
1/28/2010 11:08 PM
 

I have a DNN module that I am working on which includes a complex form with rules about sections of the form that should be shown or hidden based on options the user selects. I am currently showing and hiding those sections using div tags and jQuery, and it all works perfectly.  On the same form are a couple of controls that require a postback to the server (a pair of date pickers - when the user changes the date selection, the contents of a combo box change to reflect available options within that date range). I have partial rendering turned on for the module, and I really want to keep it that way because of the better user experience.

My problem is that as soon as the user makes a chage that triggers an asynchronous postback, any divs that were previously hidden become visible again. If I could trigger some script following the return of the asynchronous request it would be fine, as I could just reset all of the divs to the correct state.  I can't seem to make that happen, though.

The suggestion I keep seeing on different blog entries is to do something like:

<script type="text/javascript">
    Sys.WebForms.PageRequestManager.getInstance().add_endRequest(EndRequestHandler);
    function EndRequestHandler(sender, args) {
        // js code here; runs only on async postbacks
    }
</script>

When I try that, however, the EndRequestHandler never seems to fire.  Am I missing something? Any suggestions on how to handle this would be greatly appreciated.

 
New Post
1/29/2010 10:33 AM
 

Ok, I figured out how to make it work.  I wasn't explicitly using an update panel, just letting DNN handle it with partial rendering.  What worked for me was:

1. Change the divs from <div id="accommodationsPanel"> to <div id="accommodationsPanel" runat="server">


2. Change the jQuery references from $("#accommodationsPanel") to $("div[id$='accommodationsPanel']")  because running it at the server changes the client id, but the lovely id$ selector matches on the end of the generated client id.


3. Add a method in the code behind with code like:
            if (this.rblChoice.SelectedValue == ChoiceNone)
            {
                this.accommodationsPanel.Attributes.Add("style", "display:none;");
            }
            else
            {
                this.accommodationsPanel.Attributes.Add("style", "display:block;");
            }

Just setting the .Visible property on the server side doesn't work, because setting .Visible to false causes the entire block to not be rendered at all and therefore breaks the client side scripts looking for the divs.

With that combination of things, the client side scripts continue to fire and work properly, and anytime there is an asynchronous callback they get set properly again during the round trip.

 
Previous
 
Next
HomeHomeDevelopment and...Development and...Building ExtensionsBuilding ExtensionsModulesModulesHow to fire a script after an asynchronous postback?How to fire a script after an asynchronous postback?


These Forums are dedicated to discussion of DNN Platform and Evoq Solutions.

For the benefit of the community and to protect the integrity of the ecosystem, please observe the following posting guidelines:

  1. No Advertising. This includes promotion of commercial and non-commercial products or services which are not directly related to DNN.
  2. No vendor trolling / poaching. If someone posts about a vendor issue, allow the vendor or other customers to respond. Any post that looks like trolling / poaching will be removed.
  3. Discussion or promotion of DNN Platform product releases under a different brand name are strictly prohibited.
  4. No Flaming or Trolling.
  5. No Profanity, Racism, or Prejudice.
  6. Site Moderators have the final word on approving / removing a thread or post or comment.
  7. English language posting only, please.
What is Liquid Content?
Find Out
What is Liquid Content?
Find Out
What is Liquid Content?
Find Out