开发者

two components with the same id can't be added to the application

Hello I am having problems with 2 popupcontrol extenders. They are used in conjuction with a webservice to display the detail information from a database. Each extender gets information a from 2 different tables. The extenders both work fine except when they have run across a row that has the same pri开发者_运维技巧mary key number. Here is what the code is (I removed most of the info) to hopefully make it faster to view:

<cc1:TabContainer ID="TabContainer1" runat="server" ActiveTabIndex="0" CssClass="ajax__myTab" Width="100%" ScrollBars="Horizontal">
    <cc1:TabPanel ID="TabPanel5" runat="server" HeaderText="" Enabled="true">
        <HeaderTemplate>Agent Info </HeaderTemplate>
        <ContentTemplate>
        <asp:GridView ID="GridViewClosedProducts" runat="server" AutoGenerateColumns="False" 
            BackColor="White" BorderColor="#999999" BorderStyle="Solid" BorderWidth="1px" 
            CellPadding="5" CellSpacing="1" DataKeyNames="Pkey" 
            DataSourceID="SqlDataSourceGRClosedProds" ForeColor="Black" GridLines="Vertical" 
            AllowSorting="True" PageSize="20">
            <FooterStyle BackColor="#CCCCCC" />
            <Columns>
                <asp:TemplateField>
                    <ItemTemplate>
                        <asp:Image runat="server" BorderStyle="None" ID="Image1" ImageUrl="Images\MagnifyingClass.gif" />
                        <cc1:PopupControlExtender ID="PopupControlExtender1" runat="server" PopupControlID="Panel1" TargetControlID="Image1" DynamicContextKey='<%# Eval("Pkey") %>' DynamicControlID="Panel1" DynamicServiceMethod="GetClosedComment" Position="right">
                        </cc1:PopupControlExtender>
                        <asp:Panel ID="Panel1" runat="server">
                        </asp:Panel>
                    </ItemTemplate>
                    <HeaderStyle VerticalAlign="Top" BorderWidth="0px" />
                    <ItemStyle BorderWidth="0px" HorizontalAlign="Center" />
                </asp:TemplateField>
            </Columns>
            <PagerStyle BackColor="#999999" ForeColor="Black" HorizontalAlign="Center" />
            <SelectedRowStyle BackColor="#000099" Font-Bold="True" ForeColor="White" />
            <HeaderStyle BackColor="Silver" Font-Bold="True" ForeColor="Black" />
            <AlternatingRowStyle BackColor="#CCCCCC" />
        </asp:GridView>
        <asp:SqlDataSource ID="SqlDataSourceGRClosedProds" runat="server" 
            ConnectionString="<%$ ConnectionStrings:EUCNET00722 %>" 
            SelectCommand="SELECT * FROM [tblClosedProducts] WHERE ([AgentMainPkey] = @AgentMainPkey) ORDER BY Product, DateClosed"> 
            <SelectParameters>
                <asp:ControlParameter ControlID="hdnPkey" Name="AgentMainPkey" PropertyName="Value" Type="Int32" />
           </SelectParameters>
        </asp:SqlDataSource>
</ContentTemplate>
</cc1:TabPanel>

    <cc1:TabPanel ID="TabPanel3" runat="server" HeaderText="" Enabled="true">
        <HeaderTemplate>Agent Info </HeaderTemplate>
        <ContentTemplate>
<asp:GridView ID="GridViewUpdates" runat="server" AutoGenerateColumns="False" BackColor="White" 
    BorderColor="#999999" BorderStyle="Solid" BorderWidth="1px" CellPadding="5" 
    CellSpacing="1" DataKeyNames="Pkey" DataSourceID="SqlDataSourceGRUpdates" ForeColor="Black" 
    GridLines="Vertical">
    <AlternatingRowStyle BackColor="#CCCCCC" />
    <Columns>
        <asp:TemplateField>
            <ItemTemplate>
                 <asp:Image runat="server" BorderStyle="None" ID="Image1" ImageUrl="Images\MagnifyingClass.gif" />
                <cc1:PopupControlExtender ID="PopupControlExtenderGVU" runat="server" PopupControlID="Panel1" TargetControlID="Image1" DynamicContextKey='<%# Eval("Pkey") %>' DynamicControlID="Panel1" DynamicServiceMethod="GetUpdateComment" Position="right">
                </cc1:PopupControlExtender>
                <asp:Panel ID="Panel1" runat="server">
                </asp:Panel>
            </ItemTemplate>
            <HeaderStyle VerticalAlign="Top" BorderWidth="0px" />
            <ItemStyle BorderWidth="0px" HorizontalAlign="Center" />
        </asp:TemplateField>
    </Columns>
   <FooterStyle BackColor="#CCCCCC" />
    <HeaderStyle BackColor="Silver" Font-Bold="True" ForeColor="Black" />
   <PagerStyle BackColor="#999999" ForeColor="Black" HorizontalAlign="Center" />
   <SelectedRowStyle BackColor="#000099" Font-Bold="True" ForeColor="White" />
</asp:GridView>
<asp:SqlDataSource ID="SqlDataSourceGRUpdates" runat="server" ConnectionString="<%$ ConnectionStrings:EUCNET00722 %>" SelectCommand="SELECT * FROM [tblComments] WHERE ([AgentMainPkey] = @AgentMainPkey) ORDER BY DateOfComment DESC" DeleteCommand="delete from tblComments where pkey = @pkey">
    <SelectParameters>
        <asp:ControlParameter ControlID="hdnPkey" Name="AgentMainPkey" PropertyName="Value" Type="Int32" />
    </SelectParameters>
</asp:SqlDataSource>
</ContentTemplate>
</cc1:TabPanel>
</cc1:TabContainer>

** Code behind

Protected Sub GridViewClosedProducts_RowCreated(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewRowEventArgs) Handles GridViewClosedProducts.RowCreated

    If e.Row.RowType = DataControlRowType.DataRow Then

        If Not e.Row.DataItem Is Nothing Then

            Dim pce As PopupControlExtender = TryCast(e.Row.FindControl("PopupControlExtender1"), PopupControlExtender)

            Dim MyPkey As String = e.Row.DataItem("Pkey")
            pce.BehaviorID = MyPkey

            Dim img As Image = DirectCast(e.Row.FindControl("Image1"), Image)

            Dim OnMouseOverScript As String = String.Format("$find('{0}').showPopup();", MyPkey)
            Dim OnMouseOutScript As String = String.Format("$find('{0}').hidePopup();", MyPkey)

            img.Attributes.Add("onmouseover", OnMouseOverScript)
            img.Attributes.Add("onmouseout", OnMouseOutScript)

        End If

    End If

 End Sub


Protected Sub GridViewUpdates_RowCreated(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewRowEventArgs) Handles GridViewUpdates.RowCreated

    If e.Row.RowType = DataControlRowType.DataRow Then

        If Not e.Row.DataItem Is Nothing Then
            Dim pceGVU As PopupControlExtender = TryCast(e.Row.FindControl("PopupControlExtenderGVU"), PopupControlExtender)

            Dim MyPkey As String = e.Row.DataItem("Pkey")
            pceGVU.BehaviorID = MyPkey

            Dim img As Image = DirectCast(e.Row.FindControl("Image1"), Image)

            Dim OnMouseOverScript As String = String.Format("$find('{0}').showPopup();", MyPkey)
            Dim OnMouseOutScript As String = String.Format("$find('{0}').hidePopup();", MyPkey)

            img.Attributes.Add("onmouseover", OnMouseOverScript)
            img.Attributes.Add("onmouseout", OnMouseOutScript)

        End If

    End If

End Sub

This is how the code is rendered by IE

<img id="ctl00_ContentPlaceHolder2_TabContainer1_TabPanel5_GridViewClosedProducts_ctl10_Image1" onmouseover="$find('48').showPopup();" onmouseout="$find('48').hidePopup();" src="Images\MagnifyingClass.gif" style="border-style:None;border-width:0px;" />
<img id="ctl00_ContentPlaceHolder2_TabContainer1_TabPanel3_GridViewUpdates_ctl02_Image1" onmouseover="$find('48').showPopup();" onmouseout="$find('48').hidePopup();" src="Images\MagnifyingClass.gif" style="border-style:None;border-width:0px;" />


@Mike: If it's possible to store the previous row's Pkey value in a variable, then I'd do something like this --

Dim MyPkey As Integer = e.Row.DataItem("Pkey")
Dim MyStoredPkey As Integer

If MyPkey <> MyStoredPkey Then
   MyStoredPkey = MyPkey
Else   
   MyPkey = MyPkey + 1
End If

pceGVU.BehaviorID = MyPkey

...to increment the Pkey should it be found in the stored variable.

Note: This is practically pseudo-code since I have very little ASP.NET experience.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜