我希望能够通过javascript以及它的面板返回以编程方式生成的可折叠面板扩展器等等。我已经让面板和相关的表格正常运行,但是当我尝试连接cpe时,它会断开。并返回错误:
cpe面板等由WebService生成,我试图让JS写出webservice动态返回到特定字段的内容
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);
}
}
我该如何解决这个问题?
答案 0 :(得分:0)
您似乎需要一个Page
对象和ScriptManager
来呈现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();
奥利弗