[英]How to fire OnClick event in nested panels with ModalPopupExtender?
I have the following scenario: 我有以下情况:
UpdatePanel1
-> UpdatePanel2
-> UpdatePanel3
: UpdatePanel1
> UpdatePanel2
> UpdatePanel3
:
Inside it I have a GridView
with a following column definition: 在其中,我有一个带有以下列定义的GridView
:
<ItemTemplate>
<asp:ImageButton ID="img_btnEdit" runat="server" AlternateText="Edit"
CausesValidation="false" Height="15px" OnClientClick='<%#Eval("TranValueId", "PopulateEditTransValuesMDPP({0}); return false;") %>'
ImageUrl="~/Images/document_edit.png" Width="15px" />
</ItemTemplate>
When clicked, a ModalPopupExtender
should open, but first I need to retrieve the boundfield of the clicked row. 单击时,应打开ModalPopupExtender
,但首先我需要检索单击行的边界域。
JS function: JS功能:
function PopulateEditTransValuesMDPP(id) {
var btPopupLoad = document.getElementById('<%= btPopupLoad.ClientID %>');
var hdnlblModalPopuphelper = document.getElementById('<%= hdnlblModalPopuphelper.ClientID %>');
if (id != null) {
hdnlblModalPopuphelper.innerHTML = id;
}
btPopupLoad.click();
}
Here is the rest of the HTML code that resides in the same UpdatePanel
as the GridView
: 这是与GridView
驻留在同一UpdatePanel
的其余HTML代码 :
<asp:Label ID="hdnlblModalPopuphelper" runat="server" Text="" style="display:none;"></asp:Label>
<asp:Button ID="btPopupLoad" runat="server" Text="Load" OnClick="btPopupLoad_Click" style="display:none;" />
<ajaxToolkit:ModalPopupExtender ID="modppOpen" runat="server" TargetControlID="btPopupLoad"
PopupControlID="pnlModPPDefaultValueEditing" BackgroundCssClass="modalBackground" OkControlID="btnCloseModalPopup"
DropShadow="true" />
<asp:Panel ID="pnlModPPDefaultValueEditing" runat="server" CssClass="aspnetForm" Width="80%">
<asp:UpdatePanel ID="updpanEditDefaultValue" runat="server" UpdateMode="Conditional">
<Triggers>
<asp:AsyncPostBackTrigger ControlID="btnSaveEditingTransValueDefaultValue" />
</Triggers>
(...)
Problem Description: Everything works fine, except that the OnClick
Event (the server side event) of the btPopupLoad
is not triggered! 问题描述:除了未触发btPopupLoad
的OnClick
事件(服务器端事件)以外,其他所有操作都正常!
The only way I made the OnClick
event to get fired was by setting the UseSubmitBehaviour="false"
in its definition but that's causing a postback and the ModalPopup
dissapears. 我触发OnClick
事件的唯一方法是在其定义中设置UseSubmitBehaviour="false"
,但这会导致回发并且ModalPopup
消失。 So basically I want the OnClick Event
to be triggered and in the same time keep the ModalPopup
still opened. 因此,基本上,我希望触发OnClick Event
,同时保持ModalPopup
仍然打开。
Help, please? 请帮助?
I figured it out by myself so if anyone ever runs into this, this is how it worked for me: 我自己弄清楚了,所以如果有人碰到这个,这就是它的工作方式:
Instead of 代替
<ItemTemplate>
<asp:ImageButton ID="img_btnEdit" runat="server" AlternateText="Edit"
CausesValidation="false" Height="15px" OnClientClick='<%#Eval("TranValueId", "PopulateEditTransValuesMDPP({0}); return false;") %>'
ImageUrl="~/Images/document_edit.png" Width="15px" />
</ItemTemplate>
(which uses a hacky way of opening a modal popup anyway) just do this: (无论如何,它都会使用一种很hack的方式打开模式弹出窗口):
HTML HTML
<asp:ImageButton ID="img_btnEdit" runat="server" AlternateText="Edit" CommandArgument="<%# ((GridViewRow) Container).RowIndex %>" CommandName="Editing"
CausesValidation="false" Height="15px"
ImageUrl="~/Images/document_edit.png" Width="15px" />
C#: C#:
protected void gvTransValues_RowCommand(object sender, GridViewCommandEventArgs e)
{
if (e.CommandName == "Editing")
{
int index = Convert.ToInt32(e.CommandArgument);
GridViewRow row = gvTransValues.Rows[index];
//do whatever you need here
modppOpen.Show();
}
}
What I basically did was to replace the whole hacky way of using hidden buttons or labels and just prompt the modalpopup straight from the click of the button using CommandName
and CommandArguments
of the RowCommand
event of the gridview
. 我基本上所做的是替换使用隐藏按钮或标签的整个方法,而只需使用gridview
的RowCommand
事件的CommandName
和CommandArguments
从按钮的单击中直接提示modalpopup。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.