How to refresh DataGrid and DropDown on main page after hiding modal popup
- by James
Hi,
I am adding records to a database from a modal popup. After hiding the modal popup, the page has not been refreshed even though I have Rebound the controls. I have reviewed a few postings on the web about this but the solution still evades me. I have attached my code after removing some of the extra detail... It seems I need to cause a postback but I don't know what needs to be changed. Some posts have talked about the extender being misplaced. Anyway, thank you
James
<asp:Content ID="Content1" ContentPlaceHolderID="Head" Runat="Server">
<div class="divBorder">
<asp:DataGrid id="dgrSessionFolders" runat="server" BorderWidth="2px"
BorderStyle="Solid" BorderColor="#C0C0FF"
Font-Names="Arial" Font-Bold="True" Font-Size="8pt" GridLines="Horizontal" AutoGenerateColumns="False"
PageSize="9999" AllowPaging="False" OnItemCommand="dgrSessionFolders_Command" OnItemDataBound="CheckSessionFolderStatus"
HorizontalAlign="Left" ForeColor="Blue" ShowFooter="True" CellPadding="2"
OnSortCommand="dgrSessionFolders_Sort" AllowSorting="True">
</asp:DataGrid>
</div>
<asp:Label ID="Errormsg" runat="server" ForeColor="#CC0000"></asp:Label>
<asp:UpdatePanel ID="UpdatePanel1" runat="server" RenderMode="Inline" ChildrenAsTriggers="false" UpdateMode="Conditional">
<Triggers>
<asp:AsyncPostBackTrigger ControlID="btnEditTopic" />
<asp:AsyncPostBackTrigger ControlID="btnAdd" />
<asp:AsyncPostBackTrigger ControlID="btnUpdate" />
<asp:AsyncPostBackTrigger ControlID="btnDelete" />
<asp:AsyncPostBackTrigger ControlID="btnClear" />
<asp:AsyncPostBackTrigger ControlID="btnAddTopic" />
<asp:AsyncPostBackTrigger ControlID="btnUpdateTopic" />
<asp:AsyncPostBackTrigger ControlID="btnDeleteTopic" />
</Triggers>
<ContentTemplate>
<asp:panel id="pnl" runat="server" HorizontalAlign="Center" Height="48px" Width="100%" >
<asp:ImageButton ID="btnEditTopic" runat="server" AlternateText="Edit Topic"
ImageUrl="~/App_Themes/Common/images/BtnEditTopic.jpg" Height="28px">
</asp:ImageButton>
<cc1:ModalPopupExtender ID="btnEditTopic_ModalPopupExtender" runat="server" BackgroundCssClass="modalBackground"
DropShadow="true" Enabled="true" PopupControlID="pnlEditTopic" TargetControlID="btnEditTopicHidden"
CancelControlID="btnEditTopicClose">
</cc1:ModalPopupExtender>
<asp:ImageButton ID="btnAdd" runat="server" AlternateText="Add Folder"
ImageUrl="~/App_Themes/Common/images/BtnAddFolder.jpg" Height="28px">
</asp:ImageButton>
<asp:ImageButton ID="btnUpdate" runat="server" AlternateText="Update Folder"
ImageUrl="~/App_Themes/Common/images/BtnUpdateFolder.jpg" Height="28px">
</asp:ImageButton>
<asp:ImageButton ID="btnDelete" runat="server" AlternateText="Delete Folder"
ImageUrl="~/App_Themes/Common/images/BtnDeleteFolder.jpg" Height="28px">
</asp:ImageButton>
<asp:ImageButton ID="BtnClear" runat="server" AlternateText="Clear Screen Input Fields"
ImageUrl="~/App_Themes/Common/images/BtnAddMode.jpg" Height="28px">
</asp:ImageButton>
<asp:Button ID="btnEditTopicHidden" runat="server" Enabled="false" Text="" Style="visibility: hidden" />
</asp:panel>
<asp:Panel ID="pnlEditTopic" runat="server" CssClass="modalPopupEditTopic" Style="display: none;" >
<table cellspacing="0" class="borderTable0" width="100%" style="">
<tr>
<td colspan="10" class="Subhdr" align="center" style="width:100%">
<asp:label id="lblTopicScreenHdr" Cssclass="ScreenHdr" runat="server">Topic Maintenance</asp:label>
</td>
</tr>
<tr>
<td colspan="6">
<asp:Label ID="TopicPopErrorMsg" runat="server" ForeColor="#CC0000"> </asp:Label>
</td>
</tr>
<tr style="height:4px">
<td colspan="6" align="center">
<asp:ImageButton ID="btnAddTopic" runat="server" AlternateText="Add Topic"
ImageUrl="~/App_Themes/Common/images/BtnApply.jpg" Height="28px">
</asp:ImageButton>
<asp:ImageButton ID="btnUpdateTopic" runat="server" AlternateText="Update Topic"
ImageUrl="~/App_Themes/Common/images/BtnApply.jpg" Height="28px">
</asp:ImageButton>
<asp:ImageButton ID="btnDeleteTopic" runat="server" AlternateText="Delete Topic"
ImageUrl="~/App_Themes/Common/images/BtnDelete.jpg" Height="28px">
</asp:ImageButton>
<asp:ImageButton ID="btnEditTopicClose" runat="server" AlternateText="Close Edit Topic Popup"
ImageUrl="~/App_Themes/Common/images/BtnCancel.jpg" Height="28px">
</asp:ImageButton>
</td>
</tr>
</table>
</asp:Panel>
</ContentTemplate>
</asp:UpdatePanel>
Private Sub btnAddTopic_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnAddTopic.Click
'Add the Topic table entry
AddTopic()
'Display an informational message
Errormsg.Text = "The Topic has been successfully added, thank you! "
Errormsg.ForeColor = Drawing.Color.Blue
'Rebind the Topic Drop Down and set to added Topic
ddlSessionTopic.DataBind()
ddlSessionTopic.SelectedValue = drTopic("TOPC_ID")
'Rebind the Session Folders grid
RebindGrid()
'Hide the Topic Popup
btnEditTopic_ModalPopupExtender.Hide()
End Sub
Private Sub RebindGrid()
cnnSQL = New SqlConnection(strConnection)
cmdSQL = New SqlCommand("GetSessionFoldersForGrid", cnnSQL)
cmdSQL.CommandType = CommandType.StoredProcedure
cmdSQL.Parameters.Clear()
cnnSQL.Open()
dadSQL = New SqlDataAdapter(cmdSQL)
dadSQL.SelectCommand = cmdSQL
dadSQL.Fill(dtSessionFolderGrid)
cnnSQL.Close()
dvSessionFolderGrid = dtSessionFolderGrid.DefaultView
dvSessionFolderGrid.Sort = String.Format("{0} {1}{2}", so.Sortfield, so.SortDirection, so.SortSuffix)
dgrSessionFolders.DataSource = dvSessionFolderGrid
dgrSessionFolders.DataBind()
End Sub