将 ASP.net 控件添加到 JQuery 对话框无法正确呈现
您好,我见过很多与此类似的问题,但所有问题都已通过将对话框添加回页面的主窗体中来解决。这不能解决以下问题:
在我的 Aspx 文件中,我定义了一段代码,如下所示:
<asp:UpdatePanel runat="server" ID="RadAjaxPanel2" UpdateMode="always">
<ContentTemplate>
<div id="areaFilterDialog" runat="server">
</div>
</ContentTemplate>
</asp:UpdatePanel>
并且我有以下 javascript / jquery 来初始化对话框
$("#areaFilterDialog").dialog({
bgiframe: true,
autoOpen: false,
resizable: false,
modal: true,
draggable: true,
closeOnEscape: true,
width: 630,
open: function (type, data) {
dialogOpen = true;
$(this).parent().appendTo("form");
}
});
});
,该对话框将对话框的元素附加到父级的表单中页。
在 .cs 文件中,我将内容添加到元素中,如下所示:
var departmentCode = e.DepartmentCode;
var summaryType = e.SummaryType;
var summaryCode = e.SummaryCode;
var totalName = e.TotalName;
var view = this.TemplateControl.LoadControl(".\\WebControls\\FilteredAreaRadGrid.ascx") as FilteredAreaRadGrid;
using (var businessManager = new BusinessManager(new DALConnection(this.DalConnectionString)))
{
view.DataSource = businessManager.GetData(departmentCode, summaryType, summaryCode, string.Empty);
this.AreaFilterDialog.Controls.Add(view);
}
并通过使用 ScriptManager 注册以下启动脚本来显示 JQuery UI 对话框:
var script = string.Format("ShowAttendanceFilterPopup('{0}');", totalName);
ScriptManager.RegisterStartupScript(
this.Page,
this.Page.GetType(),
"tmp",
string.Format("<script type='text/javascript'>{0}</script>", script),
false);
它调用以下 javascript/jquery:
function ShowAttendanceFilterPopup(summaryName) {
$("#areaFilterDialog").data('title.dialog', summaryName);
$('#areaFilterDialog').dialog("open");
$('#areaFilterDialog').dialog("enable");
}
问题是 html 应该具有附加到对话框实际上只是附加到页面顶部,并且根本不显示对话框。如果我在显示之前不将控件添加到对话框中,则对话框将正确显示。
我已经尝试过使用当前添加的内容,即包含 Telerik RadGrid 的 UserControl,但也包含标准的 asp 按钮,并且两者具有相同的行为。
有人对我做错了什么或者更好的事情有任何想法,解决这个问题吗?
非常感谢,
罗布
Hi I've seen quite a few similar questions to this but all have been resolved by adding the dialog back into the page's main form. This doesn't resolve the following problem:
In my Aspx file, I've defined a segment of code as following:
<asp:UpdatePanel runat="server" ID="RadAjaxPanel2" UpdateMode="always">
<ContentTemplate>
<div id="areaFilterDialog" runat="server">
</div>
</ContentTemplate>
</asp:UpdatePanel>
and I've got the following javascript / jquery to initialise the dialog
$("#areaFilterDialog").dialog({
bgiframe: true,
autoOpen: false,
resizable: false,
modal: true,
draggable: true,
closeOnEscape: true,
width: 630,
open: function (type, data) {
dialogOpen = true;
$(this).parent().appendTo("form");
}
});
});
which appends the dialog's element to the form on the parent page.
In a .cs file, I add content to the element as follows:
var departmentCode = e.DepartmentCode;
var summaryType = e.SummaryType;
var summaryCode = e.SummaryCode;
var totalName = e.TotalName;
var view = this.TemplateControl.LoadControl(".\\WebControls\\FilteredAreaRadGrid.ascx") as FilteredAreaRadGrid;
using (var businessManager = new BusinessManager(new DALConnection(this.DalConnectionString)))
{
view.DataSource = businessManager.GetData(departmentCode, summaryType, summaryCode, string.Empty);
this.AreaFilterDialog.Controls.Add(view);
}
and I make the JQuery UI Dialog show by registering the following startup script with the ScriptManager:
var script = string.Format("ShowAttendanceFilterPopup('{0}');", totalName);
ScriptManager.RegisterStartupScript(
this.Page,
this.Page.GetType(),
"tmp",
string.Format("<script type='text/javascript'>{0}</script>", script),
false);
which calls the following javascript / jquery:
function ShowAttendanceFilterPopup(summaryName) {
$("#areaFilterDialog").data('title.dialog', summaryName);
$('#areaFilterDialog').dialog("open");
$('#areaFilterDialog').dialog("enable");
}
The problem is that the html which should have been appended to the dialog is actually just appended to the top of the page, and the dialog box is not shown at all. If i don't add a Control to the dialog before I show it, the dialog displays correctly.
I've tried this with what I add currently, which is a UserControl containing a Telerik RadGrid, but also with a standard asp button, and both have the same behaviour.
Anyone got any ideas to what I'm doing incorrectly or even better, a solution to this problem?
Thanks a lot,
Rob
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
也许尝试一下:
我没有使用过 Telerik Ajax 面板,但我猜想是这样的:
将 div 放在 AjaxPanel ContentTemplate 中并向其中添加视图控件对我来说似乎并不正确。
Perhaps try:
I've not used the Telerik Ajax Panels but I'm guessing something like:
Having the div inside the AjaxPanel ContentTemplate and adding the view Control to it just doesn't seem right to me.