更新时间:2022-06-16 03:46:19
你意识到 RptClientDetails
是服务器端控件?当您绑定到 BindJobs
的绑定时,它是绑定的,但您不返回生成的HTML。
You do realize that RptClientDetails
is a server side control? When you are binding to it in your call to BindJobs
it is binding but you are not returning the generated HTML.
您需要在中继器的HTML被绑定到AJAX后返回。然后在您的成功处理程序中,将HTML注入到您想要显示 Repeater
的位置。
You need to return the Repeater's HTML after it has been bound in your AJAX. Then in your success handler, inject the HTML into the place where you want the Repeater
to be displayed.
I建议您查看 Rick Strahl's 关于如何执行此操作的信息:
I would recommend checking out Rick Strahl's post regarding how to do this:
jQuery and ASP.NET Article Part 2
最简单的方法是将AJAX放在一起,并使用 UpdatePanel
。只需将 Repeater
和您的按钮
与 UpdatePanel
该调用将由框架处理,并为您注入新的HTML。这比使用jQuery / AJAX方法要重一些,但是它需要几乎0个代码。
The easiest way would be to drop the AJAX all together and use an UpdatePanel
. Just wrap your Repeater
and your Button
with an UpdatePanel
and the call will be handled by the framework and the new HTML will be injected for you. It's a little heavier than doing it the jQuery/AJAX method but it takes almost 0 code.
EG:
<!-- Your other controls -->
<asp:UpdatePanel ID="yourPanel" runat="server">
<ContentTemplate>
<!-- Your Repeater HERE -->
<!-- Your Button HERE and server side make it call your bind -->
</ContentTemplate>
</asp:UpdatePanel>
<!-- rest of your controls -->
编辑:
如果要渲染控件,以便您可以在回复中发送回来,您可以执行以下操作:
If you want to render the control so that you can send it back in your response you can do:
// This will get your Repeaters rendered HTML
StringBuilder sb = new StringBuilder();
StringWriter tw = new StringWriter(sb);
HtmlTextWriter hw = new HtmlTextWriter(tw);
RptClientDetails.RenderControl(hw);
string yourReatersRenderedHtml = sb.ToString();
然后,您可以在AJAX调用中返回此字符串,然后使用成功方法将其注入到 div
或其他一些占位符。老实说, UpdatePanel
更容易,如果您寻找最简单的方法,我建议使用它,而不是非常担心使用 UpdatePanel
。
You could then return this string in the AJAX call and then use the success method to inject it into a div
or some other place holder. Honestly, the UpdatePanel
is far easier and I would recommend it if your looking for the easiest way to do this and are not really worried about the performance impact of using an UpdatePanel
.