从.aspx调用.aspx.cs中的函数 [英] call function in .aspx.cs from .aspx

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

问题描述

嗨...



我想调用.aspx中.aspx.cs页面中的函数。并且我需要将我在文本框中输入的文本反映到.cs页面。

i尝试了一些代码,但它没有用完......

< br $>


< asp:TextBox ID =TextBox1runat =serveronkeyup =<%= CheckCharCounter(this))%> ; /> 







in .cs page



  public   void  CheckCharCounter( string  text)
{

}





如何我可以调用函数吗?



提前感谢...

解决方案

如果此服务器端函数是只是一个辅助函数,并没有引用任何内部控件,即你可以让它静态,然后你可以从javascript异步调用。这篇文章展示了它是如何完成的。



适用于初学者的AJAX(第3部分) - 在ASP.NET网站中调用服务器端方法和从JavaScript使用Web服务 [ ^ ]


你可以通过使用JQuery实现它,下面是一些使用jquery脚本调用方法后面的示例代码



 <   script    类型  =  text / javascript >  


(function(){
debugger;

hi...

i want to call function which is in .aspx.cs page from .aspx. and at the i need to reflect th text i entered in text box to .cs page.
i tried some code but it doesn''t work out...


<asp:TextBox ID="TextBox1" runat="server"   onkeyup="<%=CheckCharCounter(this))%>" />  




in .cs page

public void CheckCharCounter(string text)
   {

   }



how can i call function?

thanks in advance...

解决方案

If this server side function is just a helper function and does not refer to any controls inside i.e. you can afford to make it static then you can call is asynchronously from javascript. Here is the article that shows how it can be done.

AJAX for Beginners (Part 3) - Calling Server Side Methods and Consuming Web Services from JavaScript in an ASP.NET website[^]


You can achieve it by using JQuery, following is some sample code to call code behind method using jquery script

<script type="text/javascript">


(function () { debugger;


这篇关于从.aspx调用.aspx.cs中的函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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