从JavaScript调用一个C#方法 [英] Call a c# method from Javascript

查看:144
本文介绍了从JavaScript调用一个C#方法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好我想打电话给一个C#方法。我已经tryed用的webmethod,但在C#中的方法我不会查看在文本框或其他控件。

Hi i want to call a C# method.. I already tryed with webmethod, but in the c# method i will not have acces to textbox or others controls.

这是我没有成功完成..
http://www.singingeels.com/文章/ Using_Page_Methods_in_ASPNET_AJAX.aspx

this is how i done without success.. http://www.singingeels.com/Articles/Using_Page_Methods_in_ASPNET_AJAX.aspx

通过静态的作品,但我想不带静电,这样我就可以访问该控件在ASPX和验证的页面。

With static works, but i want without static, so i can access to the controls in the aspx and validate the page.

我该怎么办呢?

推荐答案

您不能做这只是一个JavaScript调用,你需要回传,如果你想访问控制的页面上。该页面不知道什么是在文本框例如,除非您发送数据,这些数据的JavaScript调用不会做,而是一种形式或AJAX提交的意志。

You can't do this with just a javascript call, you need to postback if you want access to the controls on the page. The page doesn't know what's in the textboxes for example unless you send that data, which a javascript call won't do, but a form or AJAX submit will.

我建议一个JavaScript验证库,像这样。只是一定要还验证服务器上,一旦你提交检查禁用了JavaScript(或恶意行为试图绕过您的验证......)谁的用户。

I'd suggest a javascript validation library, something like this. Just be sure to also validate on the server once you've submitted to check for users who have javascript disabled (or are maliciously trying to bypass your validation...).

这篇关于从JavaScript调用一个C#方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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