【发布时间】:2010-08-15 13:34:31
【问题描述】:
我使用 ASP.NET C# 和 AJAX Professional (http://www.ajaxpro.info)
1) 我有一个带有 Panel 控件的 div 容器,Panel 控件应该包含将在代码隐藏函数中生成的 DropDownList:
<div id="divDDL" runat="server">
<asp:Panel ID="Panel1" runat="server">
</asp:Panel>
</div>
2) 我有一个 JS 脚本函数“getDDL”,它将数据发送到代码隐藏函数,然后它使用生成的 Panel 和 DropDownList 控件接收响应:
function getDDL(lng)
{
MyCodebahindClass.GetDDL(0, lng, callbackDDL);
//callbackDDL is a response function
}
function callbackDDL(response)
{
//here the response with the generated DropDownList and Panel control comes to the div element
document.getElementById('<%=divDDL.ClientID %>').innerHTML = response.value;
}
3) Codebehind 函数“GetDDL”必须返回 Panel 控件内生成的 DropDownList:
[Ajax.AjaxMethod]
public Panel GetDDL(int itemId, int lng)
{
PanelID = Panel1.ID;
DropDownList rubricDDL = new DropDownList();
rubricDDL.ID = "Fashionable_Catheter";
rubricDDL.DataTextField = "title";
rubricDDL.DataValueField = "id";
rubricDDL.DataSource = %LINQ STUFF%;
rubricDDL.DataBind();
panelID.Controls.Add(rubricDDL);
return panelID;
}
4) 当我尝试通过 JS 响应获取生成的 Panel 和 DropDownList 时,我只收到文本“System.Web.UI.Design.Panel”或类似的内容,尝试仅生成 DropDownList - 出现类似的文本"System.Web.UI.Design.DropDownList"。
但是当我调用代码隐藏函数来获取这两个控件时,我看到它们没有任何问题。为什么我不能通过 JS 获取它们?我做的一切都很好,调试了一百万次,没有发现任何问题,我不知道 JavaScript 有什么问题? 非常感谢任何帮助。
【问题讨论】:
标签: c# javascript asp.net ajax ajaxpro