通过 ajax/javascript 返回 CollapsiblePanelExtender

发布于 2024-07-25 23:46:27 字数 2218 浏览 8 评论 0原文

我希望能够通过 javascript 返回以编程方式生成的可折叠面板扩展器及其面板等。 我已经让面板和相关的表格运行得很好,但是当我尝试连接 CPE 时,它坏了。 并返回错误:

cpe 面板等由 WebService 生成,我试图让 JS 动态地将 Webservice 返回到特定字段的内容

Microsoft JScript 运行时错误:Sys.Net.WebServiceFailedException:服务器方法“Sub_Menu_Helper”失败并出现以下错误:System.InvalidOperationException-页面不能为空。 请确保此操作是在 ASP.NET 请求的上下文中执行的。

                {
                    Label somelabel = new Label();
                    somelabel.ID = somenumber.ToString();
                    somelabel.Text = somenumber.ToString();
                    subpnlContent.Controls.Add(somelabel);
                    ++somenumber;
                }

                CollapsiblePanelExtender cpeMenuLast = new CollapsiblePanelExtenderEx();
                cpeMenuLast.ID = "subcpe" + strMenuId + strParentHierarchyIds;
                cpeMenuLast.TargetControlID = "subpnlContent" + strParentMenuId + "_" + strMenuId;
                cpeMenuLast.ExpandControlID = "cellContent" + strParentMenuId + "_" + strMenuId;
                cpeMenuLast.CollapseControlID = "cellContent" + strParentMenuId + "_" + strMenuId;
                cpeMenuLast.Collapsed = bCollapsed;
                cpeMenuLast.TextLabelID = strMenuName;
                cpeMenuLast.ExpandedText = m_strButtonLabelHide;
                cpeMenuLast.CollapsedText = m_strButtonLabelShow;
                cpeMenuLast.ImageControlID = "imglnk" + strMenuId;
                cpeMenuLast.CollapsedImage = "~/App_Themes/default/nbExpand.gif";
                cpeMenuLast.ExpandedImage = "~/App_Themes/default/nbCollapse.gif";
                cpeMenuLast.SuppressPostBack = true;
                cpeMenuLast.ScrollContents = false;

                //Add Everything
                cellSubMenu.Controls.Add(subpnlContent);
                cellSubMenu.Controls.Add(cpeMenuLast);
                row.Cells.Add(cellSubMenu);
                tbl.Rows.Add(row);

                using (StringWriter sw = new StringWriter(sb))
                {
                    using (HtmlTextWriter tw = new HtmlTextWriter(sw))
                    {
                        tbl.RenderControl(tw);
                    }
                }

我该如何解决此问题?

I would like to be able to return a programmatically generated collapsible panel extender through javascript along with it's panel and so on. I've got the panel and associated tables going through just fine however when I try and attach the cpe it breaks. and returns an error:

The cpe panel and such are being generaged by a WebService and I'm trying to get JS to write what the webservice returns to a particular field dynamically

Microsoft JScript runtime error: Sys.Net.WebServiceFailedException: The server method 'Sub_Menu_Helper' failed with the following error: System.InvalidOperationException-- Page cannot be null. Please ensure that this operation is being performed in the context of an ASP.NET request.

                {
                    Label somelabel = new Label();
                    somelabel.ID = somenumber.ToString();
                    somelabel.Text = somenumber.ToString();
                    subpnlContent.Controls.Add(somelabel);
                    ++somenumber;
                }

                CollapsiblePanelExtender cpeMenuLast = new CollapsiblePanelExtenderEx();
                cpeMenuLast.ID = "subcpe" + strMenuId + strParentHierarchyIds;
                cpeMenuLast.TargetControlID = "subpnlContent" + strParentMenuId + "_" + strMenuId;
                cpeMenuLast.ExpandControlID = "cellContent" + strParentMenuId + "_" + strMenuId;
                cpeMenuLast.CollapseControlID = "cellContent" + strParentMenuId + "_" + strMenuId;
                cpeMenuLast.Collapsed = bCollapsed;
                cpeMenuLast.TextLabelID = strMenuName;
                cpeMenuLast.ExpandedText = m_strButtonLabelHide;
                cpeMenuLast.CollapsedText = m_strButtonLabelShow;
                cpeMenuLast.ImageControlID = "imglnk" + strMenuId;
                cpeMenuLast.CollapsedImage = "~/App_Themes/default/nbExpand.gif";
                cpeMenuLast.ExpandedImage = "~/App_Themes/default/nbCollapse.gif";
                cpeMenuLast.SuppressPostBack = true;
                cpeMenuLast.ScrollContents = false;

                //Add Everything
                cellSubMenu.Controls.Add(subpnlContent);
                cellSubMenu.Controls.Add(cpeMenuLast);
                row.Cells.Add(cellSubMenu);
                tbl.Rows.Add(row);

                using (StringWriter sw = new StringWriter(sb))
                {
                    using (HtmlTextWriter tw = new HtmlTextWriter(sw))
                    {
                        tbl.RenderControl(tw);
                    }
                }

How can I fix this?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

一桥轻雨一伞开 2024-08-01 23:46:27

看起来您需要一个带有 ScriptManagerPage 对象来呈现 CollapsiblePanelExtender,这是有道理的,因为您需要一些脚本才能使其正常工作。

所以也许您可以尝试以下方式来渲染您的表格:

var page = new Page();
page.Controls.Add(new ScriptManager());
page.Controls.Add(tbl);
var writer = new StringWriter();
HttpContext.Current.Server.Execute(page, writer, false);
return writer.ToString();

Oliver

Looks like you need a Page object with a ScriptManager to render the CollapsiblePanelExtender, which makes sense since you need some script for it to work properly.

So maybe you can try the following way to render your table:

var page = new Page();
page.Controls.Add(new ScriptManager());
page.Controls.Add(tbl);
var writer = new StringWriter();
HttpContext.Current.Server.Execute(page, writer, false);
return writer.ToString();

Oliver

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文