如何避免模态干扰按钮单击事件? [英] How do I get around modal interfering with button click event?

查看:92
本文介绍了如何避免模态干扰按钮单击事件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的ASP.Net Web窗体应用程序中,我有一个按钮,该按钮应该启动ajaxToolKit: ModalPopupExtender模态.

In my ASP.Net Web Form App, I have a button, and that button is suppose to launch an ajaxToolKit: ModalPopupExtender modal.

<asp:Button ID="uxTicketHistoryButton" runat="server" Text="Show Ticket History"  style="color: blue;" OnClick="uxTicketHistoryButton_Click"/>&nbsp;
<ajaxToolkit:ModalPopupExtender ID="uxTicketHistoryModal" runat="server" PopupControlID="Panel1" TargetControlID="uxTicketHistoryButton"CancelControlID="btnClose" BackgroundCssClass="modalBackground"></ajaxToolkit:ModalPopupExtender>
<asp:Panel ID="Panel1" runat="server" CssClass="modalPopup" align="center" style = "display:none">
....
</asp:Panel ID>

我之前曾问过

I had asked a previous question on how to insert C# variable values into the modal, but it seems my problem there is that the modal seems to be interfering with my button click event function; essentially keeping it from firing. The function is suppose to get the data I need to plug into the modal once the button is clicked and the modal launched.

protected void uxTicketHistoryButton_Click(object sender, EventArgs e)
{
    DataTable ticketHist = _dtMgr.GetContactInfoByName(uxContactDropdownList.SelectedValue);
    string rName = ticketHist.Rows[0]["RequestorName"].ToString();
    string rPhone = ticketHist.Rows[0]["RequestorPhone"].ToString();
    ....
}

我在调试时注意到一些奇怪的事情:1)在调试时,我在字符串变量上设置了断点(以查看返回的值).单击按钮后,它就越过了断点(我想这意味着它没有触发"该代码.2)我可以从_Click函数内部删除所有代码,并且当我单击按钮时,模式仍会启动3)如果我注释掉模式代码并单击按钮,则_Click事件代码会正常运行,并且我可以看到字符串变量的值.因此,我假设我有模式集的方式(我怀疑它与使用TargetControlID="uxTicketHistoryButton"有关)是问题所在.如何避免模态干扰按钮单击事件?我在这里做错了什么?

I have noticed several odd things while debugging: 1) I put break points on the string variables (to see what the values were being returned) while debugging. After clicking the button, it goes right over the breakpoints (I assume that means its not "firing" that code.2) I can remove all of the code from inside the _Click function and the modal still launches when I click the button 3) If I comment out the modal code and click the button, the _Click event code fires fine and I can see the values for the string variables. So, I am assuming that the way I have the modal set (I suspect its related to using TargetControlID="uxTicketHistoryButton") is the problem. How do I get around my modal interfering with button click event? What am I doing wrong here?

推荐答案

好像您发现了其中一个ajaxToolkit

Looks like you found one of those ajaxToolkit quirks. Try this:

创建一个隐藏按钮:

<asp:button id="hiddenButton" runat="server" style="display:none;" />

将Extender更改为目标按钮:

Change your Extender to target said button:

TargetControlID="hiddenButton"

然后在_Click事件中,显示模式:

Then in your _Click event, show the modal:

protected void uxTicketHistoryButton_Click(object sender, EventArgs e)
{
    DataTable ticketHist = _dtMgr.GetContactInfoByName(uxContactDropdownList.SelectedValue);
    string rName = ticketHist.Rows[0]["RequestorName"].ToString();
    string rPhone = ticketHist.Rows[0]["RequestorPhone"].ToString();
    ....

    uxTicketHistoryModal.Show();
}

这篇关于如何避免模态干扰按钮单击事件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆