我使用的是devExpress 11.2和ASP.NET 4.0。请耐心等待我冗长的问题描述。
我创建了一个包含ASPxPopup control(ID="myPopup")的用户控件
<dx:ASPxPopupControl ID="myPopup" runat="server" ... </dx:ASPxPopupControl>
以及其他控制。我还实现了一个公共方法ShowPopup(),它在其中执行myPopup.ShowOnPageLoad=true来显示这个弹出窗口。然后在我的ASPX页面中注册并引用此用户控件。我将此用户控件放入ASPxRoundPanel中ID="myUC"的表格单元格中
在这个页面中,我有一个ASPxGridView,我在其中创建了一个自定义命令按钮,如下所示:
<dx:GridViewCommandColumn VisibleIndex="0" Width="30px" Caption="" ButtonType="Image">
<CustomButtons>
<dx:GridViewCommandColumnCustomButton ID="cmd">
<Image Url="~/Images/OK.png" />
</dx:GridViewCommandColumnCustomButton>
</CustomButtons>
</dx:GridViewCommandColumn>
ClientSideEvents定义为
<ClientSideEvents BeginCallback="OnDevExpressBeginCallback" EndCallback="OnDevExpressEndCallback">
我想在单击此图像按钮时弹出我的用户控件。请注意,此ASPxGridView还提供插入/编辑/删除功能。
有两种方法可以满足这一要求。
1为了确保ASPxGridView正确处理其内置命令(Insert等),我需要设置EnableCallBacks="True"
,然后设置OnCustomButtonCallback="OnmyASPxGridView_CustomButtonCallback"
来处理来自代码后面的图像按钮的点击事件。我从代码后面调用了myUC.ShowPopup(),并调试到这里。但是,弹出窗口不会显示。如果我设置了EnableCallBacks="False"
,那么弹出窗口显示的正是我所期望的。
这种方法的问题是不可接受的,因为内置命令无法正常工作。所以问题是,当EnableCallBacks="True"
时,我如何从代码后面显示用户控件中的弹出控件?
2第二种方法是从客户端显示弹出窗口。我首先设置了EnableCallBacks="True"
,以确保我的内置命令正常工作。然后我将ClientSideEvents定义为
<ClientSideEvents BeginCallback="OnDevExpressBeginCallback" EndCallback="OnDevExpressEndCallback" CustomButtonClick="jsfnShowPopUpControl"/>
并删除了OnCustomButtonCallback事件。
我实现了如下的javascript函数jsfnShowPopUpControl:
function jsfnShowPopUpControl(s, e) {
// next, find access control inside user control
**var myPopupName = document.getElementById('<%=myUC.FindControl("myPopup").ClientID %>');**
if (myPopupName != null) {
myPopupName.Show();
myPopupName.PerformCallback(e);
}
else {
alert("Data error encountered"); // cannot find popup
return; //
}}
这种方法的关键部分是找到位于用户控件中的devexpress弹出控件。不幸的是,getElementById函数在我的用户控件中找不到下面的控件,因此弹出窗口也没有显示。
请帮忙,让我知道我在两种不同的方法中做错了什么。
非常感谢。
参考这些-当用户点击按钮时显示DevExpress AspOpUpControl
如何在客户端上显示ASPxPopupControl的窗口
要解决此问题,我建议您使用ASPxClientPopupControl.ShowWindow方法。
对于同一个scanerio,你想实现我所做的。已将ClientInstanceName属性分配给页面上的某个唯一名称包括用户控件,现在您可以在任何地方自由访问该对象在html中通过javascript。
允许您将弹出窗口的ClientInstanceName设置为"MainASPxClientPopupControl"。因此,应该可以在您的主页上使用它,如下所示:
MainASPxClientPopupControl.Show();
此主题的参考:ASPxPopupControl-无法从页面获取弹出窗口的实例