CSS Adapters cause multiple PostBacks in IE

Rate It (2)

Last post 02-08-2008 12:24 AM by Antilles128. 23 replies.

Sort Posts:

  • CSS Adapters cause multiple PostBacks in IE

    04-18-2007, 11:15 PM
    • Member
      128 point Member
    • steve harman
    • Member since 07-10-2006, 3:32 AM
    • Posts 38

    Hello CSS Adapter team (and Adapter users)!

    Recently I've been trying to use CSS Adapters along with the Membership/Roles/Provider controls and I've come across an issue where the Adapters cause the page to PostBack twice when using IE. (I tested using IE7 and FF 2.0... but others have confirmed the issue exists in IE6 as well).

    For example, when using the CreateUserWizard and it's Adapter, clicking the submit button (which kicks off the CreateUserWizardStep) causes the page to PostBack twice in a row. From an end-user point of view an error message is displayed on the screen, and rightly so. By stepping through the code in debug mode, I was able to verify that the first PostBack successfully created a user (and the user shows up in the aspnet_Membership table). However when they wizard tries to create the user for the 2nd PostBack it fails b/c the user already exists. Hence, an error is thrown and shown to the user.

    A similar situation occurs with the PasswordRecovery control - the password is actually reset twice, and two emails are sent to the user.

    You can confirm the double PostBack using Fiddler.

    1. fire up Fiddler and go to a page using one of the above controls (and their respective Adapter of course).
    2. Use the control.
    3. Look in the Fiddler "HTTP Sessions" window and you'll see duplicate POST requests for the same page.

    Others have reported the same issue, though they didn't root-cause it as being a double-PostBack issue. See here (http://forums.asp.net/thread/1638129.aspx). The only "solution" I've found so far is to disable the Control Adapter for the CreateUserWizard and PasswordRecovery controls.

    Oh, and I do apologize for coming off a bit rude in the other post(s)... it was late, I was tired and frustrated... but now I'm in a much better state of mind.

    So, to recap:

    • using RTM version of CSS Adapters
    • using asp.net 2.0 Membership/Profile/Roles controls with CSS Adapters
    • Membership controls + CSS Adapters work fine with FF 2.0
    • some (possibly all?) Membership controls + CSS Adapters cause double PostBack with IE7 (and others have confirmed same issue with IE6).

    Please let me know if there is anything I can to do help resolve this issue.

    Thank You!
    -Steve

     

     

  • Re: CSS Adapters cause multiple PostBacks in IE

    04-19-2007, 1:31 AM
    • Member
      25 point Member
    • oswin
    • Member since 09-07-2005, 9:19 AM
    • Posts 9
    I'm facing the same issue with the CreateUserWizard too. Sad Hopefully there will be a fix for this soon!
  • Re: CSS Adapters cause multiple PostBacks in IE

    04-19-2007, 3:11 PM
    • Member
      128 point Member
    • steve harman
    • Member since 07-10-2006, 3:32 AM
    • Posts 38

    How did I miss this? http://www.codeplex.com/cssfriendly

    As best I can tell, the CSS Friendly Adapters are now hosted and run from CodePlex - meaning all bug reports, suggestions, etc... should be submitted over there.

    Can someone at this forum (Russ?) confirm that? And if so... I'll get busy over there so we can try to get this issue fixed.

    Thanks all!
     

  • Re: CSS Adapters cause multiple PostBacks in IE

    04-19-2007, 3:30 PM
    • Contributor
      3,298 point Contributor
    • Russ Helfand
    • Member since 09-14-2005, 6:22 PM
    • Groovybits.com
    • Posts 741
  • Re: CSS Adapters cause multiple PostBacks in IE

    04-21-2007, 1:12 PM
    • Member
      32 point Member
    • ticanaer
    • Member since 11-20-2006, 8:14 PM
    • Wellington, New Zealand
    • Posts 11

    Well this is my first ever forum post so please forgive me if it is a bit verbose or lacking in any way Smile

    After spending a bit of time debugging the double postback problem with the CreateUserWizardAdapter I've found that it's caused by a slight problem with the html that is being rendered out for the create user button and I have come up with a fix for it that involves changing the CSS Control Adapter code. The solution for this problem can also be used to fix the double postback problems caused by the PasswordRecoveryAdapter, ChangePasswordAdapter, and LoginAdapter. Hopefully someone that looks after the sourcecode for the CSS Adapter project adds the fix to the project soon because it is affecting quite a few people!

    Double Postback Problem - Cause (skip this if you just want the fix!):

    Buttons that reside within the controls that are adapted by the CSS Control Adapters, for example the CreateUserWizard.CreateUserButton, are rendered out differently depending on the button type (which is set for example via CreateUserWizard.CreateUserButtonType = ButtonType.Link). The default button type used by the membership controls is Button. The following html controls are rendered out for the different System.Web.UI.WebControls.ButtonType enum values:

    ButtonType.Button: input, type=submit
    ButtonType.Image: input, type=image
    ButtonType.Link: anchor

    Both of the input controls will automatically cause the form that they reside within to be posted back to the server when they are clicked, whereas the anchor will not - instead it needs some javascript to cause a postback. This is where the problem is - all three html controls are rendered out with javascript attached to post the form back to the server on a click event, which allows buttons of type 'Link' to work correctly but causes buttons of type 'Button' and 'Image' to postback twice - the first time due to the javascript and the second because of the native postback.

    The javascript method used to cause the postback is as follows:

    WebForm_DoPostBackWithOptions(WebForm_PostBackOptions(eventTarget, eventArgument, validation, validationGroup, actionUrl, trackFocus, clientSubmit))

    In order to stop 'Button' buttons and 'Image' buttons firing twice we just need to set the clientSubmit parameter to false when these types of buttons are rendered out.

    Other problems (specific to the CreateUserWizardAdapter control)

    Once the double postback problem was fixed two other problems popped up. The first was that users still weren't being created. This was because the id and name (which is derived from the id) being used for the create user button was missing an underscore.

    The other problem was that the cancel button didn't work. It was also missing an underscore from its name and also wasn't registered for Event Validation.


    Code change to fix the Double Postback Problem in the CreateUserWizardAdapter (applicable to the other adapters too):

    Change:

    PostBackOptions options = new PostBackOptions(btn, "", "", false, false, false, clientSubmit, true, wizard.ID);

    To:

    bool clientSubmit = (wizard.CreateUserButtonType == ButtonType.Link);
    PostBackOptions options = new PostBackOptions(btn, "", "", false, false, false, clientSubmit, true, wizard.ID);

    Code change to fix all of the problems caused by the CreateUserWizardAdapter:

    Replace the WriteCreateUserButtonPanel with the following: 
    private void WriteCreateUserButtonPanel(HtmlTextWriter writer, CreateUserWizard wizard)
    {
        string btnParentCtrlId = "__CustomNav0";
        Control btnParentCtrl = wizard.FindControl(btnParentCtrlId);
        if (btnParentCtrl != null)
        {
            string createUserBtnId = btnParentCtrlId + "_StepNextButton";
            string idWithType = WebControlAdapterExtender.MakeIdWithButtonType("StepNextButton", wizard.CreateUserButtonType);
            Control btn = btnParentCtrl.FindControl(idWithType);
            if (btn != null)
            {
                Page.ClientScript.RegisterForEventValidation(btn.UniqueID);
    
                bool clientSubmit = (wizard.CreateUserButtonType == ButtonType.Link);
    
                PostBackOptions options = new PostBackOptions(btn, "", "", false, false, false, clientSubmit, true, wizard.ID);
                string javascript = "javascript:" + Page.ClientScript.GetPostBackEventReference(options);
                javascript = Page.Server.HtmlEncode(javascript);
    
                WebControlAdapterExtender.WriteBeginDiv(writer, "AspNet-CreateUserWizard-CreateUserButtonPanel", "");
    
                Extender.WriteSubmit(writer, wizard.CreateUserButtonType, wizard.CreateUserButtonStyle.CssClass, createUserBtnId, wizard.CreateUserButtonImageUrl, javascript, wizard.CreateUserButtonText);
    
                if (wizard.DisplayCancelButton)
                {
                    string cancelBtnId = btnParentCtrlId + "_CancelButton";
                    string cancelBtnIdWithType = WebControlAdapterExtender.MakeIdWithButtonType("CancelButton", wizard.CancelButtonType);
                    Control cancelBtn = btnParentCtrl.FindControl(cancelBtnIdWithType);
                    if (cancelBtn != null)
                    {
                        Page.ClientScript.RegisterForEventValidation(cancelBtn.UniqueID);
    
                        Extender.WriteSubmit(writer, wizard.CancelButtonType, wizard.CancelButtonStyle.CssClass, cancelBtnId, wizard.CancelButtonImageUrl, "", wizard.CancelButtonText);
                    }
                }
                WebControlAdapterExtender.WriteEndDiv(writer);
            }
        }
    }

     

    So now we can all get on and do the actual stuff we were trying to achieve before we ran into this problem Smile.

    Regards,

    Tana Isaac
    Solintex Limited (NZ)
     

    Golden Rule: Whoever has the gold makes the rules.
  • Re: CSS Adapters cause multiple PostBacks in IE

    04-21-2007, 3:50 PM
    • Contributor
      3,298 point Contributor
    • Russ Helfand
    • Member since 09-14-2005, 6:22 PM
    • Groovybits.com
    • Posts 741

    Dear Tana, thank you for your posting (above). It will be great when folks start reporting back on this thread to discuss their results. I'm really hoping that you've nailed the solution finally. This one has alluded folks for a long time and has been a constant headache for many users. Again, thank you for both your proposed solution and for the detailed way in which you reported it.

    If this does, indeed, fix it for most folks (or everyone), how would you feel about joining the CodePlex project where the community now maintains these adapters? See http://forums.asp.net/thread/1609640.aspx and http://forums.asp.net/thread/1610083.aspx. You might want to contact Brian Demarzo who kindly set up that CodePlex project and is helping to administer and run it. Brian's info registered at this forum is http://forums.asp.net/members/bdemarzo.aspx. The CodePlex project is at http://www.codeplex.com/cssfriendly.

    It is super-important that we get enough of a core of great devs contributing to this ongoing CodePlex effort so we have enough vibrancy with the adapters to keep folks interested in continuing to use them. So I'm really hoping that folks like you will agree to at least consider making a few contributions via the CodePlex mechanism. In any case, I want to applaud your proposed solution (above) and its thoughtful analysis.

    Russ Helfand
    Groovybits.com
  • Re: CSS Adapters cause multiple PostBacks in IE

    04-22-2007, 12:33 AM
    • Member
      32 point Member
    • ticanaer
    • Member since 11-20-2006, 8:14 PM
    • Wellington, New Zealand
    • Posts 11

    Cheers for the compliment Russ and the invitation to contribute to the project. I am happy to help out where possible as I have enjoyed the benefits of using the CSS Adapters in several projects now and it would only be fair to give something back in return. I'll flick Brian a message now and ask him to sign me up.

     
    Regards,

    Tana 

    Golden Rule: Whoever has the gold makes the rules.
  • Re: CSS Adapters cause multiple PostBacks in IE

    05-01-2007, 10:06 AM
    • Member
      435 point Member
    • bdemarzo
    • Member since 07-02-2002, 8:05 AM
    • New York
    • Posts 168

    Has anyone tried implementing this fix and did an analysis to see if it (1) fixes the problem and (2) doesn't break anything? It seemed OK in my testing, but that's far from comprehensive.

     

  • Re: CSS Adapters cause multiple PostBacks in IE

    05-01-2007, 10:16 AM
    • Member
      128 point Member
    • steve harman
    • Member since 07-10-2006, 3:32 AM
    • Posts 38

    I applied the changes to an app that I'm working on and they seem to have solved the issues described. I've did a cursory glance at the other controls and didn't notice anything wrong with them after making the changes... but as you said, that's far from being completely tested.

    Probably the best thing would be to get the changes into CodePlex (I'll submit a patch if you let me know what patch format you want) with the changes so they can be applied and at least that will get the changes into a build so others can easily test/use them.

    Thoughts?
     

  • Re: CSS Adapters cause multiple PostBacks in IE

    05-01-2007, 10:35 AM
    • Member
      435 point Member
    • bdemarzo
    • Member since 07-02-2002, 8:05 AM
    • New York
    • Posts 168

    Patch format? I don't think CodePlex has one. Just send me the updated files and I'll apply them and look at diffs locally.

    Actually I've already added the patched code referenced above in a local version -- I just haven't checked in the changes. I guess it's time to do so to get more feedback on them.

     

  • Re: CSS Adapters cause multiple PostBacks in IE

    05-01-2007, 10:48 AM
    • Member
      128 point Member
    • steve harman
    • Member since 07-10-2006, 3:32 AM
    • Posts 38

    >> Patch format? I don't think CodePlex has one.

    Right... it's actually TFS that lacks built-in patch generation and application (which is yet another reason it is a bad choice for an OSS code repostiory/management tool), but that's for another thread, another time... like the one Ayende has been having as of late. Smile

    Anyhow, I didn't know if you used WinMerge (my fav) or some other graphical diff tool that is able to generate and apply patches. If so I could send you the patch that way. But if you've already applied the changes locally, then I suppose there is no point in me duplicating your work when you could just them directly into the repository... unless you'd rather do it that way?

  • Re: CSS Adapters cause multiple PostBacks in IE

    05-01-2007, 10:53 AM
    • Member
      435 point Member
    • bdemarzo
    • Member since 07-02-2002, 8:05 AM
    • New York
    • Posts 168

    I'm a heavy Subversion user (and reader of Ayende's blog, for that matter) so I have most diff tools installed. I use TortoiseMerge most often (quick and easy) but have others installed.

    Probably best to send over your patch file and I'll toss it into my local install (which isn't on the PC I'm at right now) so I can compare our changes and make sure we cover both bases. Once I do it I'll check it in and we can compare notes.

     

  • Re: CSS Adapters cause multiple PostBacks in IE

    05-17-2007, 2:45 PM
    • Member
      2 point Member
    • hanifv
    • Member since 05-16-2007, 3:43 PM
    • Posts 1

     

    Hello. I am using CSS Adapter for one of my site and I am facing the same problem with CreateUser Adaptor. I am using VB.NET so i translated the WriteCreateUserButtonPanel method that you posted and replaced it in my code. But now the user is not getting creating. Can anyone help me ? It would be great if someone could update the adaptor and make it available for others to download.

     Thanks

  • Re: CSS Adapters cause multiple PostBacks in IE

    05-20-2007, 7:06 AM
    • Member
      32 point Member
    • ticanaer
    • Member since 11-20-2006, 8:14 PM
    • Wellington, New Zealand
    • Posts 11

    Hi there,

    Have you tried debugging the code when you click the create button? How about giving us some more info, like:

    - Is the form posting back to server (i.e. it's not getting stopped by javascript validation)?

    - If you examine the Request.Form items collection do you see the values that you entered on the screen?

    - If you examine the properties on the CreateUser control after the page load event fires are they populated with the values that you entered?

    It might be worth posting a snippet of your code up so that we can have a look at it too - assuming it doesn't contain any sensitive information that is.

    Cheers,

    Tana

    Golden Rule: Whoever has the gold makes the rules.
  • Re: CSS Adapters cause multiple PostBacks in IE

    07-06-2007, 8:18 AM
    • Member
      20 point Member
    • danadanny
    • Member since 01-03-2007, 10:13 AM
    • Posts 54

    Hi Tana,

    I have difficulty getting ChangePassword control to work properly, ie, user enters correct current password and valid new password, new password is updated in DB but control shows error.

     How can I go about implementing the above-mentioned code? Where should I place them?

     Thanks

Page 1 of 2 (24 items) 1 2 Next >