开发者

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

开发者 https://www.devze.com 2023-03-03 03:41 出处:网络
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 co

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 alr开发者_运维百科eady 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.


Check the rest of the aspx file as well as the designer.vb file and see if a control with that same ID is already present.

Alternatively, set a breakpoint just before you add the control to the page (placeholder) collection and recursively interrogate the page controls to see if a control with the same ID already exists.


Not exactly sure why it was an issue but eventually I found that setting the ClientID mode of the control to AutoID solved the problem. My suspicion is that there were validation controls being generated by the control that had conflicting identities but I wasn't able to prove it.

0

精彩评论

暂无评论...
验证码 换一张
取 消