ASP.NET:ModalPopupExtender prevents按钮点击事件从发射 [英] ASP.NET: ModalPopupExtender prevents button click event from firing
问题描述
下面是我想要做什么:点击我的页面,这反过来又使(2)事情发生的一个按钮:
- 在显示一个ModalPopup至prevent从pressing任何按钮或改变值用户
- 在背后叫我的方法code,隐藏ModalPopup完成后,
下面是ASP的标记:
< ASP:UpdatePanel的ID =UpdatePanel2=服务器ChildrenAsTriggers =真
的UpdateMode =始终>
<触发器>
< ASP:AsyncPostBackTrigger控件ID =btnSaveData事件名称=点击/>
< /触发器>
<的ContentTemplate>
< ASP:面板ID =pnlHidden=服务器的风格=显示:无;>
< DIV>
< H1>节能...< / H1>
< / DIV>
< / ASP:面板>
&所述; CC1:ModalPopupExtender ID =modalPopup
BackgroundCssClass =modalBackground=服务器
的TargetControlID =btnSaveDataPopupControlID =pnlHidden
BehaviorID =的ShowModal>
< / CC1:ModalPopupExtender>
< ASP:按钮的ID =btnSaveData=服务器文本=保存数据
的OnClick =btnSaveData_Click/>
< /的ContentTemplate>
< / ASP:UpdatePanel的>
现在,这里的背后是C#code我的code:
保护无效btnSaveData_Click(对象发件人,EventArgs的)
{
UpdateUserData(GetLoggedInUser());
modalPopup.Enabled = FALSE;
}
为什么没有这项工作?该ModalPopup显示完美,但btnSaveData_Click事件永远不会触发。
更新:第一个建议并没有为我工作。我也想你的第二个建议(因为它适用于我)。在我结束一个微小的差别是,有我的模式面板(pnlHidden)上没有按钮 - 它只是一个消息。我曾尝试使用JavaScript事件在客户端,其中至少有我的服务器端事件同时做火。这是个好消息,但我似乎无法找到或抢在ModalPopupExtender或其BehaviorID的句柄。这不能正常工作:
函数showOverlay(){
VAR弹出= $查找('modalPopup');
popup.show();
}
弹出总是等于空。
最后更新:这是我得到这个工作(采取具体的使用注意事项的OnClientClick及的OnClick的)最终解决方案:
< ASP:UpdatePanel的ID =UpdatePanel2=服务器ChildrenAsTriggers =真
的UpdateMode =始终>
<触发器>
< ASP:AsyncPostBackTrigger控件ID =btnSaveData事件名称=点击/>
< /触发器>
<的ContentTemplate>
< ASP:面板ID =pnlHidden=服务器的风格=显示:无;>
< DIV>
< H1>节能...< / H1>
< / DIV>
< / ASP:面板>
&所述; CC1:ModalPopupExtender ID =modalPopup
BackgroundCssClass =modalBackground=服务器
的TargetControlID =hdnFieldPopupControlID =pnlHidden
BehaviorID =的ShowModal>
< ASP:HiddenField ID =hdnField=服务器/>
< / CC1:ModalPopupExtender>
< ASP:按钮的ID =btnSaveData=服务器文本=保存数据
的OnClientClick =的ShowModal();的OnClick =btnSaveData_Click/>
< /的ContentTemplate>
< / ASP:UpdatePanel的>
使用这个JavaScript函数:
函数的ShowModal(){$找到('的ShowModal)显示()。 }
...这$ C $落后C:
保护无效btnSaveData_Click(对象发件人,EventArgs的)
{
UpdateUserData(GetLoggedInUser());
modalPopup.hide();
}
试试这个。
创建一个虚拟的隐藏字段:
< ASP:HiddenField ID =hdnField=服务器/>
在你的模式弹出申报设置的TargetControlID =hdnField。
在你btnSaveData_Click情况下,做到这一点:
modalPopup.Show();
Here is what I'm trying to do: Click a button on my page, which in turn makes (2) things happen:
- Display a ModalPopup to prevent the user from pressing any buttons or changing values
- Call my code behind method, hiding the ModalPopup when finished
Here is the ASP markup:
<asp:UpdatePanel ID="UpdatePanel2" runat="server" ChildrenAsTriggers="true"
UpdateMode="Always">
<Triggers>
<asp:AsyncPostBackTrigger ControlID="btnSaveData" EventName="Click" />
</Triggers>
<ContentTemplate>
<asp:Panel ID="pnlHidden" runat="server" style="display: none;">
<div>
<h1>Saving...</h1>
</div>
</asp:Panel>
<cc1:ModalPopupExtender ID="modalPopup"
BackgroundCssClass="modalBackground" runat="server"
TargetControlID="btnSaveData" PopupControlID="pnlHidden"
BehaviorID="ShowModal">
</cc1:ModalPopupExtender>
<asp:Button ID="btnSaveData" runat="server" Text="Save Data"
OnClick="btnSaveData_Click" />
</ContentTemplate>
</asp:UpdatePanel>
Now, here is my code behind C# code:
protected void btnSaveData_Click(object sender, EventArgs e)
{
UpdateUserData(GetLoggedInUser());
modalPopup.Enabled = false;
}
Why doesn't this work? The ModalPopup displays perfectly, but the btnSaveData_Click event NEVER fires.
UPDATE: The first suggestion did not work for me. I also tried your second suggestion (insofar as it applied to me). One minor difference on my end is that there is no button on my modal panel (pnlHidden) -- it's just a message. I did try using Javascript events on the client side, which at least did fire concurrently with my server-side event. This was good news, but I can't seem to find or grab a handle on the ModalPopupExtender or its BehaviorID. This doesn't work:
function showOverlay() {
var popup = $find('modalPopup');
popup.show();
}
popup is ALWAYS equal to null.
FINAL UPDATE: This is my final solution for getting this to work (Take specific note of the use of OnClientClick AND OnClick):
<asp:UpdatePanel ID="UpdatePanel2" runat="server" ChildrenAsTriggers="true"
UpdateMode="Always">
<Triggers>
<asp:AsyncPostBackTrigger ControlID="btnSaveData" EventName="Click" />
</Triggers>
<ContentTemplate>
<asp:Panel ID="pnlHidden" runat="server" style="display: none;">
<div>
<h1>Saving...</h1>
</div>
</asp:Panel>
<cc1:ModalPopupExtender ID="modalPopup"
BackgroundCssClass="modalBackground" runat="server"
TargetControlID="hdnField" PopupControlID="pnlHidden"
BehaviorID="ShowModal">
<asp:HiddenField ID="hdnField" runat="server" />
</cc1:ModalPopupExtender>
<asp:Button ID="btnSaveData" runat="server" Text="Save Data"
OnClientClick="showModal();" OnClick="btnSaveData_Click" />
</ContentTemplate>
</asp:UpdatePanel>
Using this Javascript function:
function showModal() { $find('ShowModal').show(); }
... And this code behind:
protected void btnSaveData_Click(object sender, EventArgs e)
{
UpdateUserData(GetLoggedInUser());
modalPopup.hide();
}
Try this.
Create a dummy hidden field:
<asp:HiddenField ID="hdnField" runat="server" />
Set the TargetcontrolID = "hdnField" in your Modal Popup declaration.
In your btnSaveData_Click event, do this:
modalPopup.Show();
这篇关于ASP.NET:ModalPopupExtender prevents按钮点击事件从发射的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!