C锐利页面中的javascript代码 [英] javascript code in C-sharp Page

查看:87
本文介绍了C锐利页面中的javascript代码的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我该如何在C语言的敏锐页面中编写javascript代码.

how can i write a javascript code in c sharp page.

推荐答案

您不能在C#中编写javascript.
不过,您可以调用javascript形式的C#.
http://msdn.microsoft.com/en-us/library/system.web.ui.page.registerclientscriptblock.aspx [ ^ ]
You cannot write javascript in C#.
Though, you can call javascript form C#.
http://msdn.microsoft.com/en-us/library/system.web.ui.page.registerclientscriptblock.aspx[^]


您的困惑可能与以下事实有关:您可能不了解客户端和服务器上发生了什么边.在某种程度上,没有"C#页面"之类的东西. C#始终在服务器端工作并生成页面.在客户端,只有HTML页面,CSS,文件和其他可通过Web浏览器访问的资源.包括JavaScript.您只需要在页面或单独的文件中编写JavaScript代码并调用它-就像通常使用HTML,JavaScript等进行的所有操作一样,无需任何服务器部分编程即可.

现在,ScriptManager是什么?实际上,这不过是某种形式的Ajax脚本生成自动化.在相同的客户端脚本模型之上的某些东西;而Ajax仅仅是JavaScript嵌入式库的重要组成部分,该库用于将由JavaScript事件触发的请求发送到HTTP服务器,而不是重新加载整个页面.

请阅读此MSDN杂志文章,以了解其工作方式和使用方法: http://msdn.microsoft. com/en-us/magazine/cc163354.aspx [ ^ ].



要回答后续问题(请参阅我的评论以回应):阅读有关JavaScript事件的信息: http://www. w3schools.com/js/js_events.asp [ ^ ].

同样,您看起来非常困惑.从仅使用HTML文件而不使用ASP.NET编写JavaScript开始.您将需要首先了解它们是如何工作的.获得它之后,您可以回到ASP.NET,Ajax,jQuery等.

—SA
Your confusion is probably related to the fact that you might not understand what happens on client and what — on server side. In a way there is no such thing as "C# page". C# always works on server side and generates the page. On a client side there are just HTML pages, CSS, file and other resource accessible via Web browser. Including JavaScript. You need just to write JavaScript code in the page or in separate file and call it — all as you normally would do using just HTML, JavaScript, etc., without any server-part programming.

Now, what is ScriptManager then? This is in fact no more than some kind of automation of generation of Ajax scripts; something on top of the same client-side scripting model; and Ajax is no more than an important part of JavaScript-embedded library used to send request to the HTTP server triggered by JavaScript events, not re-loading the whole page.

Please read this MSDN Magazine article to understand how it works and can be used: http://msdn.microsoft.com/en-us/magazine/cc163354.aspx[^].



To answer a follow-up question (see my comment in response to it): read about JavaScript events: http://www.w3schools.com/js/js_events.asp[^].

Again, you look very much confused. Start from writing JavaScript in just HTML files, without ASP.NET. You will need to understand how they work first. After you got it you can get back to ASP.NET, Ajax, jQuery, etc.

—SA


这篇关于C锐利页面中的javascript代码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆