简体   繁体   English

将JavaScript代码与“服务器端ASP.Net AJAX”一起放在哪里?

[英]Where to put javascript code with “Server-side ASP.Net AJAX”?

If I want to use ASP.Net without the Microsoft AJAX Control Toolkit or JQuery on the client-side, there are 2 possibilities according to their website ( http://www.asp.net/ajax/ ) : 如果我要在客户端使用不带Microsoft AJAX控制工具包或JQuery的ASP.Net ,则根据其网站( http://www.asp.net/ajax/ ),有两种可能:

  • Server-Side ASP.Net AJAX Programming 服务器端 ASP.Net AJAX编程
  • Client-Side ASP.NET AJAX Programming 客户端 ASP.NET AJAX编程

Client-Side programming obviously is just the javascript-side of the coin which means you could use Javascript to send requests, parse the results etc. 客户端编程显然只是硬币的javascript端,这意味着您可以使用Javascript发送请求,解析结果等。

What bothers me is the "server-side" counterpart. 困扰我的是“服务器端”的对应对象。 I understand that you can use an "UpdatePanel" to do partial page updates and such but if HTML content depends on data received by asynchronous calls or even when new content needs to be added to the DOM tree because of that, where would I insert the Javascript necessary to parse that data and add the required HTML in such a scenario? 我了解您可以使用“ UpdatePanel”进行部分页面更新,但如果HTML内容取决于异步调用接收到的数据,或者甚至由于该原因需要将新内容添加到DOM树中,我应该在哪里插入在这种情况下解析该数据并添加所需HTML所必需的Javascript?

From their website, they even make it sound like anything AJAX can be realized without using "custom" Javascript code on the client-side which seems odd to me. 在他们的网站上,他们甚至听起来好像无需在客户端使用“自定义” Javascript代码就可以实现任何AJAX,这对我来说似乎很奇怪。

Updatepanels are indeed intended to be used without any custom javascript code. 实际上,Updatepanels无需任何自定义javascript代码即可使用。 You can create your page, add an event and modify the contents of the panel just the way you would, when using a real postback (when user clicks some button and submits the page); 您可以使用真实的回发(当用户单击某些按钮并提交页面时),以与创建页面相同的方式创建页面,添加事件并修改面板的内容; so just by using things like panel.Controls.Add(new Label() { Text="Hi" }) . 因此只需使用panel.Controls.Add(new Label() { Text="Hi" })

Basically create a new UpdatePanel, add a button and a label to it, and add a Button_Click event where you do a label.Text="blah" to see this in action. 基本上,创建一个新的UpdatePanel,向其添加一个按钮和一个标签,并在其中执行label.Text="blah"操作中添加一个Button_Click事件,以查看此操作。

You use the PageRequestManager object on the client-side to listen for events generated during an asynchronous postback. 您可以在客户端上使用PageRequestManager对象来侦听异步回发过程中生成的事件。

For more information check out this overview on MSDN: 有关更多信息,请在MSDN上查看以下概述:

http://msdn.microsoft.com/en-us/library/bb386571.aspx http://msdn.microsoft.com/zh-CN/library/bb386571.aspx

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM