Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: ASP.NET
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...
Posted 20-Jan-13 21:05pm
074051.1K
Edited 20-Jan-13 23:29pm
v3
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 2

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[^]
  Permalink  
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 3

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;
            $.ajax({
                type: 'POST',
                url: 'Default.aspx/YourMethodName;,
                data: "{'args':'test'}",
                contentType: "application/json; charset=utf-8",
                dataType: "json",
                success: function (msg) {
                    //give alert if u want for success
                }
                Error:function(msg){
                    //give alert if ur functuion got some error
                }
            });
        });
    </script>
 

and your method is aspx.cs look like
using System.Web.Services; //add this namespace in your aspx.cs file

[WebMethod]
 public static ArrayList YourMethodName(string args)
 {
          // code here
 }</pre>
  Permalink  
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

  Permalink  

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
0 OriginalGriff 390
1 Sergey Alexandrovich Kryukov 329
2 Afzaal Ahmad Zeeshan 244
3 BillWoodruff 210
4 Maciej Los 192
0 OriginalGriff 5,560
1 DamithSL 4,476
2 Maciej Los 3,942
3 Kornfeld Eliyahu Peter 3,480
4 Sergey Alexandrovich Kryukov 3,175


Advertise | Privacy | Mobile
Web03 | 2.8.141216.1 | Last Updated 21 Jan 2013
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100