通过 ajax/javascript 返回 CollapsiblePanelExtender
我希望能够通过 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
看起来您需要一个带有
ScriptManager
的Page
对象来呈现CollapsiblePanelExtender
,这是有道理的,因为您需要一些脚本才能使其正常工作。所以也许您可以尝试以下方式来渲染您的表格:
Oliver
Looks like you need a
Page
object with aScriptManager
to render theCollapsiblePanelExtender
, 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:
Oliver