0

我正在从模式弹出窗口向数据库添加记录。隐藏模式弹出窗口后,页面没有刷新(即使我已经重新绑定了控件)。我已经在网上查看了一些关于此的帖子,但解决方案仍然逃避我。在删除了一些额外的细节后,我附上了我的代码。

看来我需要进行回发,但我不知道需要更改什么。一些帖子谈到了扩展器放错了位置。

<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>
&nbsp;&nbsp;&nbsp;
<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%" >
    &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
    <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">&nbsp;</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>
</asp:Content>

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
4

2 回答 2

0

如果您使用 javascript 进行回发会怎样?

Form.Submit();

或者你可以谷歌并使用这样的东西:http ://weblogs.asp.net/mnolton/archive/2003/06/04/8260.aspx

于 2009-12-07T03:43:13.987 回答
0

如果您希望重新绑定网格,则需要更新更新面板。

'添加主题表条目 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()

'添加主题表条目 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()
 UpdatePanel1.Update

'Hide the Topic Popup
btnEditTopic_ModalPopupExtender.Hide()
于 2010-04-08T01:59:00.947 回答