ASP删除按钮,单击后刷新ModalPopup

时间:2011-08-29 20:58:40

标签: asp.net vb.net modalpopup

我有ModalPopupExtenders,它显示与特定产品无关的关联。与产品关联的关联显示在tabcontainer中,旁边有删除图像按钮。当我之前测试时,我注意到我从tabcontainer中删除的关联不会显示在模态中,除非我单击浏览器中的刷新按钮。是否有一些我可以使用的代码,以便当我点击删除按钮时,它会自动刷新我的模态,以便我不会有额外的步骤?

<!-- Targets -->
<asp:TabPanel ID="tab8" runat="server" HeaderText="Targets">
<HeaderTemplate>Targets</HeaderTemplate>
    <ContentTemplate>
        <ul class="info">
        <asp:ListView ID="lvTargets" runat="server" DataSourceID="dsTargets" DataKeyNames="TargetID">   
        <ItemTemplate>
            <li><%# Eval("TargetName")%>
            <asp:ImageButton ID="DeleteTargetButton" runat="server" Style="float:right;" AlternateText="" ImageUrl="../../images/delete.png" CommandName="Delete" OnClientClick="return confirm('Are you sure you want to delete this target audience?')" />
            </li>
        </ItemTemplate>
        </asp:ListView>
        </ul>
    </ContentTemplate>
</asp:TabPanel>
</asp:TabContainer>

 <!-- Add a Target -->
      <li>
        <asp:LinkButton ID="TargetButton" runat="server">Target</asp:LinkButton>
        <asp:Panel ID="TargetPanel" runat="server" CssClass="modalPopup" Style="display:none">
            <asp:CheckBoxList ID="cbxAddTarget" runat="server" DataSourceID="dsNewTargets" DataTextField="TargetName" DataValueField="TargetID"></asp:CheckBoxList>
            <asp:Button ID="SubmitTargets" runat="server" Text="Submit" />
            <asp:Button ID="CancelSubmitTargets" runat="server" Text="Cancel" />
        </asp:Panel>
        <asp:ModalPopupExtender ID="TargetModal" runat="server" BackgroundCssClass="modalBackground" CancelControlID="CancelSubmitTargets" DropShadow="True" DynamicServicePath="" Enabled="True" PopupControlID="TargetPanel" TargetControlID="TargetButton"></asp:ModalPopupExtender>
    </li>

    Protected Sub SubmitTargets_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles SubmitTargets.Click
    DocumentModal.Hide()
    dsNewTargets.DataBind()
    For Each Target As ListItem In cbxAddTarget.Items
        If Target.Selected Then
            Dim sqlAddTarget As String = Nothing
            'SQL INSERT: TargetLink Table
            sqlAddTarget = "INSERT INTO TargetLink (ProductID, TargetID) VALUES (" & ProductID.Value & ", " & Target.Value & ")"
            sqlAddTarget.Replace("'", "''")
            Dim SqlConnection As New SqlConnection("Server=off-db1;uid=productsDB_admin;pwd=******;database=Products")
            SqlConnection.Open()
            Dim sqlCommand As New SqlCommand(sqlAddTarget, SqlConnection)
            sqlCommand.ExecuteNonQuery()
            SqlConnection.Close()
        End If
    Next
    Response.Redirect(Request.RawUrl)
End Sub   

    Protected Sub dsTargets_Deleted(ByVal sender As Object, ByVal e As SqlDataSourceStatusEventArgs)
    If e.Exception Is Nothing Then
        'rebind the new targets list to show updates
        dsNewTargets.DataBind()
    End If
End Sub

1 个答案:

答案 0 :(得分:1)

我想我明白你要做什么。当您从选项卡容器中删除项目时,请尝试重新绑定正在为添加目标列表提供的数据源控件,如下所示:

//code to delete targets from tab container

dsNewTargets.DataBind();

编辑:添加了通过数据源控件进行重新绑定的方法。

为dsTargets(您要删除的那个)添加一个OnDeleted事件处理程序。

Protected Sub dsTargets_Deleted(sender As Object, e As SqlDataSourceStatusEventArgs)
    If e.Exception Is Nothing Then
        'rebind the new targets list to show updates
        dsNewTargets.DataBind()
    End If
End Sub

编辑:数据源控件可能是缓存结果。添加了禁用缓存的代码。

尝试将以下行添加到Page_Load事件中:

Response.Cache.SetCacheability(HttpCacheability.NoCache)