[英]Modal Popup not working inside UpdatePanel
我在UpdatePanel中有一個gridview。 gridview中的一列是鏈接,單擊該鏈接應顯示模式(我正在使用zurb模式http://www.zurb.com/playground/reveal-modal-plugin )。 問題是,僅在單擊鏈接時模態僅顯示一次,而在下次單擊鏈接時,模態只會刷新頁面。 每次單擊gridview內的鏈接時,都應顯示模態。
模態腳本:
function popupModal()
{
$("a.link").click(function (e) {
e.preventDefault();
$('#myModal #modalContents').load($(this).attr('href'));
$('#myModal').reveal();
});
}
網格視圖:
<asp:ScriptManager ID="smgr" runat="server" EnablePartialRendering="true" />
<asp:UpdatePanel ID="upnlSearchResults" runat="server" RenderMode="Inline">
<ContentTemplate>
<asp:GridView ID="gvResult" runat="server" AutoGenerateColumns="false">
<Columns>
<asp:BoundField DataField="EmployeeID" HeaderText="Employee ID" />
<asp:TemplateField HeaderText="">
<ItemTemplate>
</td></tr>
<tr>
<td colspan="10">
<a href="Department.aspx" class="link">Detail Information</a>
</td>
</tr>
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
</ContentTemplate>
<Triggers>
<asp:AsyncPostBackTrigger ControlID="btnSearch" />
</Triggers>
</asp:UpdatePanel>
<div id="myModal" class="reveal-modal">
<div id="modalContents"></div>
<a class="close-reveal-modal">×</a>
</div>
綁定GridView和注冊模態彈出窗口的代碼
protected void btnSearch_Click(object sender, ImageClickEventArgs e)
{
var results = _presenter.GetEmployers();
gvResult.DataSource = results;
gvResult.DataBind();
ScriptManager.RegisterStartupScript(this.Page, this.Page.GetType(), "popUp", "popupModal();", true);
}
編輯:我試圖調試javascript和代碼中斷顯示出彈出窗口的行
function popupModal() { $("a.link").click(function (e) { e.preventDefault(); $('#myModal #modalContents').load($(this).attr('href')); $('#myModal').reveal(); -> [throws error in this line.] }); }
由於我使用的是zurb模態,因此它包含jquery.reveal.js文件,其中包含揭示功能。 函數popupModal在我單獨的js文件employee.js中。 由於錯誤消息是這樣的,例如``對象不支持IE中的屬性或方法''顯示'',我假設一旦首次顯示彈出模式,它就無法從jquery.reveal中找到顯示功能。 .js文件。
誰能幫我解決這個問題?
桑耶夫
好的,終於找到了解決方案。 不知道,但您無法在項目中兩次引用jquery.js文件。 我在Master文件中引用了我的jquery.js文件,而在Department.aspx文件中也引用了相同的引用。 擺脫了重復的jquery參考,它工作得很好。
可能發生的事情是jquery和updatepanels之間發生的相同沖突(知道您沒有使用jquery,但我確定它是同一類型的問題)。 基本上,updatepanel不會刷新整個DOM,因此永遠不會調用其他js庫的函數。 這是有關處理它的博客文章。
除非您執行以下操作,否則jQuery無法與updatePanels配合使用:
function pageLoad() {
//Your Jquery code goes here...
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.