开发者

ASP delete button to refresh ModalPopup after click

开发者 https://www.devze.com 2023-03-31 19:28 出处:网络
I have ModalPopupExtenders that show associations that are NOT tied to a specific product. The associations that ARE tied to the product are shown in a tabcontainer with delete imagebuttons next to th

I have ModalPopupExtenders that show associations that are NOT tied to a specific product. The associations that ARE tied to the product are shown in a tabcontainer with delete imagebuttons next to them. When I was testing earlier I noticed that the associations that I delete from the tabcontainer don't show up in the modal unless I click on the refresh button in my browser. Is there some code I could use that would make it so that when I click on the delete button, it will automatically refresh my Modal so that I won't have that extra step?

<!-- Targets -->
<asp:TabPanel ID="tab8" runat="server" HeaderText="Targets">
<HeaderTemplate>Targets</HeaderTemplate>
    <ContentTemplate>
        <ul class="info">
        <asp:ListView ID="lvTargets" runat="server" DataSourceID="d开发者_如何学编程sTargets" 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


I think I understand what you're trying to do. When you delete items from the tab container, try rebinding the datasource control that's feeding the add target list, like this:

//code to delete targets from tab container

dsNewTargets.DataBind();

EDIT: Added method for rebinding with delete through datasource control.

Add an OnDeleted event handler for dsTargets (the one you're deleting from).

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

EDIT: Data source control might be caching results. Added code to disable caching.

Try adding the following line to your Page_Load event:

Response.Cache.SetCacheability(HttpCacheability.NoCache)
0

精彩评论

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