刷新模式弹出窗口内的UpdatePanel

时间:2014-05-28 09:36:48

标签: c# asp.net gridview updatepanel modalpopupextender

显然我做错了什么,只是不确定是什么...... 我有一个模态弹出窗口,里面是一个更新面板,它又包含一个gridview。首次调用模态弹出窗口时,我想刷新UpdatePanel(和网格数据)。

我有代码工作,以便在按下按钮时更新面板btnHiddenJSRefresh(当前未隐藏)。但是,如果不按下按钮,我无法工作!

我已尝试点击'按钮通过Jquery $("<%= btnHiddenJSRefresh.ClientID%>")。click(); 我可以看到它被调用,但页面上没有任何反应。 与__doPostBack相同("<%= btnHiddenJSRefresh.ClientID%>","");

另外(这可能是不相关的)gridview中的删除选项在这里不起作用。在UpdatePanel之外,它工作得很好......

以下是代码,我试图将其缩减到主要问题区域

<ajaxact:modalpopupextender id="ModalPopupExtender1" runat="server"
cancelcontrolid="ClosePopup" okcontrolid="ClosePopup"
targetcontrolid="hidenSelectedDoc" popupcontrolid="THolder"
popupdraghandlecontrolid="PopupHeader" drag="true" BehaviorID="MPE" Y="0" backgroundcssclass="ModalPopupBG">

<div classs="ModalPopup" id="THolder" >
    <a id="ClosePopup" href="#">Close</a>
    <asp:Button ID="btnHiddenJSRefresh" runat="server" Text="Button" UseSubmitBehavior="false" OnClick="btnAddTag_Click" />

    <asp:UpdatePanel ID="UpdatePanel2" runat="server" ChildrenAsTriggers="false" UpdateMode="Conditional" OnLoad="UpdatePanel2_Load" >

        <ContentTemplate>            
    <asp:GridView ID="gvPageTags" runat="server" AutoGenerateColumns="False" DataSourceID="SqlDataSourcePageTags"  CssClass="TableDataHolder" DataKeyNames="CarID" >
                        <Columns>
                            <asp:BoundField DataField="FullName" HeaderText="Full Name" SortExpression="FullName" />                               
                            <asp:TemplateField HeaderText="Delete">
                                <ItemTemplate>                                           
                                        <asp:ImageButton ID="deleteButtonImg" runat="server" CommandName="Delete" Text="Delete" OnClientClick="return confirm('Are you sure you want to delete this car?');" ImageUrl="~/images/icons/DeleteIconS.png" AlternateText="Delete" />
                                </ItemTemplate>
                            </asp:TemplateField>
                        </Columns>                             
                    </asp:GridView>
        </ContentTemplate>
    </asp:UpdatePanel>

    <asp:SqlDataSource ID="SqlDataSourcePageTags" runat="server"
                    ConnectionString="<%$ ConnectionStrings:bobConnectionString %>"
                    SelectCommand="SELECT * FROM Cars WHERE (cMake = @cMake)"
                    DeleteCommand="DELETE * FROM Cars WHERE CarID = @CarID">                       
                    <SelectParameters>
                        <asp:Parameter Name="cMake" DefaultValue="0" Type="int32" />
                    </SelectParameters>
                </asp:SqlDataSource>

    </div>           

背后的代码

protected void btnAddCar_Click(object sender, EventArgs e)
    {
        SqlDataSourcePageTags.SelectParameters["cMake"].DefaultValue = hidenSelectedcMake.Value;
        SqlDataSourcePageTags.DataBind();
        gvPageTags.DataBind();
        UpdatePanel2.Update();
    }

任何想法都会很棒。

由于

1 个答案:

答案 0 :(得分:0)

拥有代码片段中引用的所有页面代码会更有帮助。在此期间,我尝试从您的描述中模拟此功能,所以如果我误解了某些内容,请纠正我。

在页面加载时,我添加了一个javascript块来检查它是否是回发。如果不是,那么我调用按钮(btnHiddenJSRefresh)点击事件一次以重新模拟模态。另外,我添加了一个按钮来弹出模态窗口,请参阅我的代码示例。最后,删除选项在此示例中正常工作。

 <%@ Register Assembly="AjaxControlToolkit" Namespace="AjaxControlToolkit" TagPrefix="cc1" %>

 <form id="form1" runat="server">

<asp:ScriptManager ID="ScriptManager1" runat="server" ScriptMode="Release">
                <Scripts>
                    <asp:ScriptReference Path="resources/jquery-1.11.0.js"/>
                </Scripts>
</asp:ScriptManager>

 <script type="text/javascript">

     $(document).ready(function () {
         var chkPostBack = '<%= Page.IsPostBack ? "true" : "false" %>';             

         if ( !Boolean.parse(chkPostBack) ) {                
             __doPostBack("<%= btnHiddenJSRefresh.ClientID %>", "");
         }
     });
</script>  


<asp:Button ID="shwmodal" runat="server" Text="show modal" 
    onclick="shwmodal_Click" />

<div classs="ModalPopup" id="THolder" >


<a id="ClosePopup" href="#">Close</a>



<asp:Button ID="btnHiddenJSRefresh" runat="server" Text="Button" style="display:none" OnClick="btnAddTag_Click" />



<asp:UpdatePanel ID="UpdatePanel2" runat="server" ChildrenAsTriggers="false" UpdateMode="Conditional" 
OnLoad="UpdatePanel2_Load" >

    <ContentTemplate>            
<asp:GridView ID="gvPageTags" runat="server" AutoGenerateColumns="False" DataSourceID="SqlDataSourcePageTags"  CssClass="TableDataHolder" DataKeyNames="RoleID" >
                    <Columns>
                        <asp:BoundField DataField="Descr" HeaderText="Descr Name" SortExpression="Descr" />                               
                        <asp:TemplateField HeaderText="Delete">
                            <ItemTemplate>                                           
                                    <asp:ImageButton ID="deleteButtonImg" runat="server" CommandName="Delete" Text="Delete" OnClientClick="return confirm('Are you sure you want to delete this car?');" ImageUrl="~/images/icons/DeleteIconS.png" AlternateText="Delete" />
                            </ItemTemplate>
                        </asp:TemplateField>
                    </Columns>                             
                </asp:GridView>
    </ContentTemplate>
</asp:UpdatePanel>

<asp:SqlDataSource ID="SqlDataSourcePageTags" runat="server"
                ConnectionString="<%$ ConnectionStrings:bobConnectionString %>"
                SelectCommand="SELECT * FROM testRoles WHERE (RoleId = @cMake)"
                DeleteCommand="DELETE FROM testRoles WHERE RoleId = @RoleId">

                <SelectParameters>
                    <asp:Parameter Name="cMake" DefaultValue="0" Type="int32" />
                </SelectParameters>
            </asp:SqlDataSource>

</div>           


 <cc1:ModalPopupExtender id="ModalPopupExtender1" runat="server"
    cancelcontrolid="ClosePopup" okcontrolid="ClosePopup"
    targetcontrolid="hidenSelectedDoc" popupcontrolid="THolder"
    popupdraghandlecontrolid="PopupHeader" drag="true" BehaviorID="MPE" Y="0" backgroundcssclass="ModalPopupBG">       
    </cc1:ModalPopupExtender>
     <asp:Button runat="server" 
        ID="hidenSelectedDoc" 
        style="display:none"/> 



</form>