Adding subclassed password recovery control to page causes “An entry with the same key already exists.” error

StackOverflow https://stackoverflow.com/questions/5913391

سؤال

I am trying to subclass the password recovery control in asp.net (4) so that I can override the behaviour of the OnVerifyingUser event but I'm having trouble adding my subclassed password recovery control into the page. I tried creating an asp:placeholder control and adding a new instance of my subclassed control to it but I just get an error that says "An entry with the same key already exists". I've tried doing this in the page_init and page_load methods but get the same error.

Here's an example of my subclass

Partial Class MyPasswordReminder
    Inherits PasswordRecovery

    Protected Overrides Sub OnVerifyingUser(e As System.Web.UI.WebControls.LoginCancelEventArgs)
        MyBase.OnVerifyingUser(e)
        'Do my stuff here
    End Sub

End Class

And here is how I'm adding it to the page.

 Private Sub Page_Init(sender As Object, e As System.EventArgs) Handles Me.Init
   Dim passwordRecoveryControl As New MyPasswordReminder
   passwordRecoveryControl.ID = "passwordRecoveryControl1"
   Placeholder1.Controls.Add(passwordRecoveryControl)
 End Sub

The UI code is just a simple:

<asp:Panel runat="server" ID="pnlMakeDefault" >
  <asp:Placeholder ID="Placeholder1" runat="server"/>
</asp:Panel>

At runtime I get the following error:

DefaultSource Error: 2 : An entry with the same key already exists. An entry with the same key already exists.

Full error:

An entry with the same key already exists. Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.ArgumentException: An entry with the same key already exists.

Source Error:

An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.

Stack Trace:

[ArgumentException: An entry with the same key already exists.]
System.Collections.Specialized.ListDictionary.Add(Object key, Object value) +7952083
System.Web.UI.ClientScriptManager.RegisterExpandoAttribute(String controlId, String attributeName, String attributeValue, Boolean encode) +337 System.Web.UI.ScriptRegistrationManager.RegisterExpandoAttribute(Control control, String controlId, String attributeName, String attributeValue, Boolean encode) +115

Does anyone know why? I suspect it's something to do with the validation controls in the base class of the password recovery control but I'm a bit at a loss as to how to proceed.

لا يوجد حل صحيح

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top