在ASP.Net和C#中从服务器端运行JavaScript [英] Run JavaScript from server side in ASP.Net and C#

查看:53
本文介绍了在ASP.Net和C#中从服务器端运行JavaScript的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何在ASP.Net服务器端运行JavaScript函数

或者我如何在JavaScript函数的侧服务器中运行函数

请F1! F1! F1! F1!

我正在使用C#

解决方案

这篇文章可能为时已晚,但对于未来的访问者来说,这仍然会有所帮助碰巧访问这个网站寻找解决方案。



我同意谢谢谢谢,但是就我所看到和理解的情况而言,jiji可能对这个问题并不十分清楚。客户端 - 服务器模型以及计算机语言(本机和解释/脚本)在服务器端和客户端上运行的模型。老实说,吉吉发布的问题令人困惑。现在让我们说清楚。



Asp.net是一种脚本技术,它运行在服务器端。它能够以文本或甚至二进制格式生成数据。另一方面,JavaScript也是一种脚本技术,但它在客户端运行。通常Javascript不在服务器端运行(但过去有服务器上运行的javascript版本)。



问题我认为'如何将javascript合并到asp.net控件'。

请记住,Javascript在客户端运行,并且由asp.net脚本生成为输出。



注意:

作为输出生成 - 当asp.net脚本生成输出时,它将被传递给另一个能够解释它的对象。在客户端 - 服务器模型中(在编程的上下文中),asp.net脚本生成的输出由客户端的浏览器解释,它是理解并能够运行javscript的浏览器。



希望我的这个小解释可以帮助那些寻求细节和解释甚至解决方案的未来访客。 =)


有服务器端JavaScript之类的东西。



参见:

< a href =http://en.wikipedia.org/wiki/Server-side_JavaScript> http://en.wikipedia.org/wiki/Server-side_JavaScript [ ^ ],

http://en.wikipedia.org/wiki/Comparison_of_server-side_JavaScript_solutions [ ^ ]。



我认为你真的不需要它。在服务器端的ASP.NET上,你有一个完整的.NET功能,你可以使用任何编译语言和强大的调试。



此外,我不现在认为服务器端JavaScript是一种常见的解决方案。我认为这很少见。在客户端,JavaScript是山上的王者(或实际上是唯一一个平台/浏览器兼容的脚本语言),但在服务器端它几乎不能与更强大的ASP.NET,Python,Ruby等竞争。我想知道为什么你需要JavaScript吗?



-SA


我解决了它

 protected void Page_Load(object sender,EventArgs e)
{
String script = @< script language = Javascript >
函数TestJScript()
{
alert('仅供测试');
}
< / script > ;
Page.RegisterClientScriptBlock(experiment,script);
Button3.Attributes.Add(onClick,TestJScript());

}





当你点击Button3时javascript函数正在运行





和另一种方式:



 Button3.Attributes.Add( onclick,javascript:alert('测试宏功能');); 





和另一种方式:



 Response.Write(<  脚本   语言  =  < span class =code-keyword> javascript  > 确认(\您确定要更改?\); <   / script  > ); 


How can I run function of JavaScript in ASP.Net server side
or how can I run function in side server in JavaScript function
Please F1! F1! F1! F1!
I am working with C#

解决方案

this post might be too late of a response but this will still be helpful for those future visitors who happen to visit this site looking for solutions.

well i agree with Sergey, however as to what i see and understand, jiji might not really have a clear idea about the client-server model and by which computer languages (native and interpreted/scripts) run on the server side and on the client side. Honestly, the problem posted by jiji was confusing. Now let's make it clear.

Asp.net is a scripting technology and it runs on the server side. It is capable of generating data in text or even in binary format. JavaScript on the other hand is also a scripting technology but which runs on the client side. Commonly Javascript doesn't run on the server side (but in the past there were versions of javascript that run on the server).

The problem i think is 'how to incorporate javascript into asp.net controls'.
Remember, Javascript runs on the client side and it is 'generated as output' by your asp.net script.

Note:
generated as output - when asp.net script generates an output it will be passed to another object that is capable of interpreting it. In the client-server model (in the context of programming), asp.net script generated output is interpreted by the client's browser and it is the browser that understands and capable of running javscript.

Hope this little explanation of mine would help those future visitors seeking for details and explanations or even solutions. =)


There is such thing as Server-side JavaScript.

See:
http://en.wikipedia.org/wiki/Server-side_JavaScript[^],
http://en.wikipedia.org/wiki/Comparison_of_server-side_JavaScript_solutions[^].

I don't think you really need it. On ASP.NET on the server side, you have a full power of .NET where you can use any compiled language and powerful debugging.

Also, I don't think Server-side JavaScript is a common solution these days. I think it's quite rare. On the client side JavaScript is the king on the mountain (or actually the only one platform/browser compatible scripting language), but on the server side it hardly can compete with more powerful ASP.NET, Python, Ruby, etc. I wonder why would you need JavaScript?

—SA


i solved it

protected void Page_Load(object sender, EventArgs e)
    {
        String script = @"<script language=""Javascript"">
                        function TestJScript()
                        {
                        alert('Just for testing');
                        }
                        </script>";
        Page.RegisterClientScriptBlock("experiment", script);
        Button3.Attributes.Add("onClick", "TestJScript()");

           }



when you click on the Button3 the javascript function is running


and another way:

Button3.Attributes.Add("onclick", "javascript:alert('Testing Macro Functionality');");



and another way:

Response.Write("<script language=javascript>confirm(\"Are you sure to change?\");</script>");


这篇关于在ASP.Net和C#中从服务器端运行JavaScript的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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