RememberMe control in Login adapter "forgets" RRS feed

  • Question

  • User-501180780 posted


    The CSS Friendly Control Adapters are wonderful (and should be standard as far as I'm concerned).

    However, I'm having a problem with the RememberMe control in the Login adapter. (I'm new to ASP.NET and the adapters, so that may be part of the problem.) When the adapters are enabled and I login in with the "Remember me next time" box checked, no cookie file (e.g. "C:\Documents and Settings\Larry\Cookies\larry@localhost[1].txt") is generated and I am not remembered the next time I log in.

    If I disable the adapters (by renaming the "App_Browsers" folder to "xApp_Browsers") and leave everything else the same, the cookie file is generated and I am remembered the next time I log in.

    The problem occurs both on my current project and on a test website created from scratch using the "ASP.NET CSS Friendly Web Site" template. I am using IE 7 for my browser. The same problem is also seen with Firefox 1.5, so I don't think it's a browser problem.

    I looked for differences in the HTML between the two pages. The only hint of a clue I had was that for the non-adapter page the control's ID is "ctl00_ContentPlaceHolder1_loginview1_login1_RememberMe" whereas for the adapted control it is "ctl00_ContentPlaceHolder1_loginview1_login1_RememberMeCheckBox". However, changing the adapter to remove the "CheckBox" suffix lead to errors when the page is viewed.

    I was wondering if anyone else has seen that problem. If you have any clues on how to debug and/or fix this, please let me know.



    Friday, September 15, 2006 12:49 PM

All replies

  • User-534056067 posted

    Hi Larry,

    Gosh, I'm sorry this slipped past us.  I hate it when basic stuff is broken in the kit.  I appreciate your being so forgiving!  And, I especially appreciate your debugging efforts (described above).  They've saved me a bunch of time.

    I'd like to ask you to clarify something, though.  You say changing the "suffix" lead to problems.  I wonder if you did that by a means other than the one I'm trying because I'm not seeing a problem when I change the suffix.  Would you mind trying what I'm trying?

    Go into your local copy of LoginAdapter.cs (or vb).  Find the WriteRememberMePanel method.  In there, you'll find a call to the method Extender.WriteCheckBox.  The fifth parameter is currently using the value "RememberMeCheckBox".  Please try changing that to "RememberMe" instead.

    Does that cause problems for you?  Does it fix the problem?

    Again, apologies for the inconvenience.  Thanks for helping us develop the right fix for this.

    Friday, September 15, 2006 5:05 PM
  • User-501180780 posted

    Hi Russ,

    Thanks for getting back so quickly. I hope we can smooth out this bump...

    I made the exact change you suggested (originally when I wrote the post and again now). When I do and then press the Login button, I get the following message:

      Server Error in '/StatusWatch' Application. -------------------------------------------------------------------------------- Invalid postback or callback argument. Event validation is enabled using in configuration or <!--Page EnableEventValidation="true"-->in a page. For security purposes, this feature verifies that arguments to postback or callback events originate from the server control that originally rendered them. If the data is valid and expected, use the ClientScriptManager.RegisterForEventValidation method in order to register the postback or callback data for validation.

    with a stack trace of:

      [ArgumentException: Invalid postback or callback argument. Event validation is enabled using in configuration or <!--Page EnableEventValidation="true"-->in a page. For security purposes, this feature verifies that arguments to postback or callback events originate from the server control that originally rendered them. If the data is valid and expected, use the ClientScriptManager.RegisterForEventValidation method in order to register the postback or callback data for validation.] System.Web.UI.ClientScriptManager.ValidateEvent(String uniqueId, String argument) +367 System.Web.UI.Control.ValidateEvent(String uniqueID, String eventArgument) +83 System.Web.UI.Control.ValidateEvent(String uniqueID) +35 System.Web.UI.WebControls.CheckBox.LoadPostData(String postDataKey, NameValueCollection postCollection) +98 System.Web.UI.WebControls.CheckBox.System.Web.UI.IPostBackDataHandler.LoadPostData(String postDataKey, NameValueCollection postCollection) +36 System.Web.UI.Page.ProcessPostData(NameValueCollection postData, Boolean fBeforeLoad) +478 System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +2549

    So what next?


    P.S. Email me if you would like to talk or IM directly.

    Saturday, September 16, 2006 2:34 PM
  • User-534056067 posted

    OK, that helps.  I think I know what's going on.  Can you give me a few hours to get back to you on this?  I need to tend to my vegetable garden for a couple of hours but when I get back I'll whip up an enhanced fix for you that takes into account the event validation stuff we are running afoul of.  Thanks for your patience. I don't think this will be too hard to solve and to patch into your existing adapter code... but give me a while to work it out.  Enjoy the day!

    Saturday, September 16, 2006 3:05 PM
  • User-534056067 posted

    OK, we're back from the veggie patch.  Things are growing nicely, though our tomatoes struggle constantly against a nasty form of the Mosaic virus that more famously plagues tabacco, http://en.wikipedia.org/wiki/Image:Tobacco_Mosaic_Virus_structure.png. Still, in all, the garden grows well.

    Now, on to the important business of getting the Remember Me checkbox to work in the Login control adapter in this kit...

    We already discussed the fact that we need to modify some of the code in App_Code\Adapters\LoginAdapter.cs (or vb).  However, the previous fix was insufficient insofar as it did not properly account for the framework's ability to validate events.  I believe the proper code looks like this:

    private void WriteRememberMePanel(HtmlTextWriter writer, Login login)
        if (login.DisplayRememberMe)
            WebControlAdapterExtender.WriteBeginDiv(writer, "AspNet-Login-RememberMePanel");
            Extender.WriteCheckBox(writer, login.LabelStyle.CssClass, login.RememberMeText, login.CheckBoxStyle.CssClass, "RememberMe", login.RememberMeSet);

    I've tested this to some degree but I am not 100% sure it going to work in your situation, too.  Would you try it and let me know?

    Saturday, September 16, 2006 7:38 PM
  • User1159918542 posted

    Hi Russ and All,

    I'm trying to create an adapter for the RadioListButton control similar to those implemented in your toolkit. However, I'm getting the same error as above (relating to event validation) on postback even though I am registering the original control for event validation. Here is the code (it is just the render method, but thats all I got in the adapter class):

            protected override void RenderContents(HtmlTextWriter writer)
    if (null != ButtonList)
    int i = 0;
    foreach (ListItem li in ButtonList.Items)
    string itemID = string.Format("{0}_{1}", ButtonList.ClientID, i++);
    writer.AddAttribute("for", itemID);

    writer.AddAttribute("id", itemID);
    writer.AddAttribute("type", "radio");
    writer.AddAttribute("name", ButtonList.UniqueID);
    writer.AddAttribute("value", li.Value);
    if (li.Selected) writer.AddAttribute("checked", "checked");



    Does anyone see anything in this code that can cause the event validation error?




    Thursday, September 21, 2006 4:46 PM
  • User-534056067 posted

    Hi Yuval,

    Try this... create a page that has the control that you want to modify.  In your case, this would be the RadioButtonList. Run that page such that the control is not adapted.  View the client-side markup ("view source" in IE or FF).  Scroll down to the bottom of the markup and look for some JavaScript that seems to relate to event validation. I wish I could be a bit more specific but I don't remember exactly what the JavaScript variables look like.  I just remember that they relate (in name) to event validation.

    These variables can give you important clues about what string you ultimately need to pass to Page.ClientScript.RegisterForEventValidation.  Your code basically looks right.  So you are on the right track.  Now you just need to figure out the correct thing to pass to RegisterForEventValidation.  If you continue to be frustrated by this, post some of the client-side script that I referred to and I'll see if I can help you spot what you need to do in the adapter code.

    Best regards,

    Thursday, September 21, 2006 6:34 PM
  • User1159918542 posted

    Thanks Russ,

    The values with and without the adapter are indeed different, but I guess that has to do with how the value gets hashed.. in any case here is the difference:


    Without adapter:

    <input type="hidden" name="__EVENTVALIDATION" id="__EVENTVALIDATION" value="/wEWCwLh6JyrAwKrwoaOBwKbvIzUDgKu4uaDCwKu4qLxAQKXzvS/CgKWzvS/CgKVzvS/CgKYod7RBgLorsehCwKyuOLUC4UtxLqb9hO17zaVg2J7Kv8DZ2W3" />

    With adapter:

    <input type="hidden" name="__EVENTVALIDATION" id="__EVENTVALIDATION" value="/wEWCALh6JyrAwKrwoaOBwKbvIzUDgKu4uaDCwKu4qLxAQKYod7RBgLorsehCwKyuOLUC9jtJdTbV2XuqO/1muZzxop9llNJ" />


    Hope this sheds some more light on whats going on.



    Thursday, September 21, 2006 10:25 PM
  • User-534056067 posted
    Actually, what I need is the script that you'll find very near that hidden <input>.  Look around for some lines of JavaScript that set up some variables whose names include something about event or validation.
    Thursday, September 21, 2006 10:32 PM
  • User1159918542 posted

    The script you are talking about does not exists in either case (with or without the adapter). The input is there, but no script block.

    Thursday, September 21, 2006 10:53 PM
  • User-534056067 posted

    Sorry.  I must be mistaken, then.  I was trying to do this out of memory, sort of.

    Give me a few hours (or until tomorrow morning) to see what I can whip up here to try to repro what you are doing. I'll get back to you soon. Cheers.

    Friday, September 22, 2006 12:02 AM
  • User-534056067 posted
    I've posted an answer for Yuval regarding how to build a RadioButtonList adapter that passes event validation at this new thread, http://forums.asp.net/thread/1407982.aspx.
    Friday, September 22, 2006 7:39 PM
  • User-48984099 posted

     <select multiple="multiple" id="CheckBoxList1"> (this why? auto writer)
     <li><input id="CheckBoxList1_0" type="checkbox" name="CheckBoxList1" value="234sdf" /><label for="CheckBoxList1_0">234sdf</label></li>
     <li><input id="CheckBoxList1_1" type="checkbox" name="CheckBoxList1" value="s2342" /><label for="CheckBoxList1_1">s2342</label></li>
     <li><input id="CheckBoxList1_2" type="checkbox" name="CheckBoxList1" value="s42342" /><label for="CheckBoxList1_2">s42342</label></li>
     <li><input id="CheckBoxList1_3" type="checkbox" name="CheckBoxList1" value="fdf" /><label for="CheckBoxList1_3">fdf</label></li>
     <li><input id="CheckBoxList1_4" type="checkbox" name="CheckBoxList1" value="df234" /><label for="CheckBoxList1_4">df234</label></li>
     <li><input id="CheckBoxList1_5" type="checkbox" name="CheckBoxList1" value="df234234" /><label for="CheckBoxList1_5">df234234</label>

    Monday, October 15, 2007 1:26 PM