无法通过AJAX响应获取生成的控件
我使用 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)代码隐藏函数“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 出了什么问题? 非常感谢任何帮助。
I use ASP.NET C# with AJAX Professional (http://www.ajaxpro.info)
1) I have a div container with Panel control, Panel control should hold DropDownList that will be generated in codebehind function:
<div id="divDDL" runat="server">
<asp:Panel ID="Panel1" runat="server">
</asp:Panel>
</div>
2) I have a JS script function "getDDL" that sends data to codebehind function and then it receives response with generated Panel and DropDownList controls:
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 function "GetDDL" must return generated DropDownList inside the Panel control:
[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) When I try to get the generated Panel and DropDownList through the JS response I receive only the text "System.Web.UI.Design.Panel" or something like that, tried to generate only DropDownList - similar text shows up "System.Web.UI.Design.DropDownList".
But when I call a codebehind function to get these two controls I see them without any problems. Why I can't get them through JS? I do everything fine, debugged million times and didn't see any problems, I can't figure out what's wrong with JavaScript?
Any help much appreciated.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
嗯,我认为你需要返回面板的渲染 html。因此,您的方法应该返回字符串,并且您需要在您的方法中渲染面板控件并返回渲染的 html。
Hmm, I think you need to return rendered html of the panel. So your method should return string and you need to render Panel Control in your method and return rendered html.
在 ajax 响应显示输出中,任何 control.html
in ajax Response display output as such that any of the control.html