简体   繁体   English

ASP.NET UserControl帮助

[英]ASP.NET UserControl Help

i have a user control that i made, and i place two instances of that control on the same page... when i interact with the first control, it updates the elements (using ajax) of the first userControl, as it should. 我有一个用户控件,并将该控件的两个实例放在同一页上...当我与第一个控件交互时,它会按需更新第一个userControl的元素(使用Ajax)。 but when i do the same thing with the second userControl, it updates the elements on the first userControl as opposed to itself!!! 但是当我对第二个userControl做同样的事情时,它会更新第一个userControl上的元素,而不是它本身! this is really strange as nothing is declared as shared, and it looks like an instantiation problem. 这真的很奇怪,因为没有任何东西被声明为共享的,而且看起来像一个实例化问题。

each userControl is wrapped around its own ajax updatepanel. 每个userControl都包装在自己的Ajax updatepanel中。

any ideas anyone? 有任何想法吗? is this a common pitfall? 这是一个常见的陷阱吗?

this is the structure of my code 这是我的代码的结构

<@ Control Language="VB" ClassName="AgeRange">
<@ Register Assembly="AjaxControlToolkit" Namespace="AjaxControlToolkit" TagPrefix="AjaxCT">

<script runat="server">

Delegate Sub NumberClickedEventHandler(ByVal sender As Object, ByVal e As EventArgs)
Public Event NumberClicked As NumberClickedEventHandler

Public Class NumberClickedEventArgs
          ' EVENT ARGS CLASS

End Class


Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs)
         ' PAGE LOAD STUFF HERE

End Sub

Public Property A FEW PROPERTIES HERE

Protected Function GetHTML(ByRef lastNumber As Byte, Optional ByVal FromNo As Byte = 18,
            Optional ByVal bForPopDown As Boolean = False, Optional ByVal bForPopUp As Boolean = False) As String

        SOME CODE HERE
End Sub

-- -

<asp:UpdatePanel ID="upAgeRange" runat="server" ChildrenAsTriggers="true" UpdateMode="Conditional" ClientIDMode="Static"
<ContentTemplate>
    <table><tr>
        <td>

            <span id="spanPopUp" runat="server">
            </span>
            <div id="dPanel" runat="server">
            </div>
            <span id="spanPopDown" runat="server">
            </span>
        </td>
    </tr>
    </table>

    <AjaxCT:HoverMenuExtender ID="hmeUp" runat="server" TargetControlID="dPanel" PopupControlID="spanPopUp" OffsetY="-200">
    </AjaxCT:HoverMenuExtender>

    <AjaxCT:HoverMenuExtender ID="hmeDown" runat="server" TargetControlID="dPanel" PopupControlID="spanPopDown" OffsetY="60">
    </AjaxCT:HoverMenuExtender>
</ContentTemplate>
</asp:UpdatePanel>

You are currently using ClientIDMode="Static" in your update panel control. 您当前在更新面板控件中使用ClientIDMode="Static" This means that the generated HTML will have duplicated IDs. 这意味着生成的HTML将具有重复的ID。 The auto-generated client-side code for the update panels needs to have distinct IDs so that it can find the correct HTML elements in which to place updates. 自动为更新面板生成的客户端代码需要具有不同的ID,以便它可以找到用于放置更新的正确HTML元素。

You probably don't need that ClientIDMode="Static" at all. 您可能根本不需要ClientIDMode="Static"

Assuming this is a Client Side issue and not Server Side. 假设这是客户端问题,而不是服务器端问题。

You'll need to ensure that both controls have unique names. 您需要确保两个控件都具有唯一的名称。

My preference is to places these controls in a <div> that has a unique class name. 我的偏好是将这些控件放在具有唯一类名的<div>中。

<div class="Ctrl1"> and <div class="ctrl2"> <div class="Ctrl1"> <div class="ctrl2"><div class="ctrl2">

I can then use findControl within the actual class I'm interested in. 然后,我可以在我感兴趣的实际类中使用findControl。

Something like $('.Ctrl2').findControl .... $('.Ctrl2').findControl ....

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM