在模态弹出框中刷新UpdatePanel
本文关键字:刷新 UpdatePanel 模态 | 更新日期: 2023-09-27 18:05:26
显然我做错了什么,只是不确定什么…我有一个模态弹出,里面是一个更新面板,其中又包含一个gridview。当第一次调用模态弹出窗口时,我想刷新UpdatePanel(和网格数据)。
我有代码工作,使面板更新时按下按钮btnHiddenJSRefresh(目前未隐藏)。但如果不按按钮,我就无法让它工作!
我试过"点击"按钮通过Jquery $("<%= btnHiddenJSRefresh。ClientID %>").click ();我可以看到它被调用了,但是页面上没有反应。__doPostBack(<%= btnHiddenJSRefresh)也是如此。ClientID %>", ");
而且(这可能是不相关的)gridview中的delete选项在这里不起作用。在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();
}
有什么主意都可以。
谢谢
拥有在代码片段中引用的所有页面代码将更有帮助。同时,我试着从你的描述中模拟这个功能,所以如果我误解了什么,请纠正我。
在页面加载时,我添加了一个javascript块来检查它是否是回发。如果不是,那么我调用按钮的(btnHiddenJSRefresh)点击事件一次刷新模态。此外,我还添加了一个按钮来弹出模态窗口,请参阅我的代码示例。最后,在这个例子中,delete选项工作得很好。
<%@ 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>