CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 6 of 6
  1. #1
    Join Date
    Dec 2007
    Location
    South Africa
    Posts
    263

    How to Call a Server side Function on the Client side Pin

    Good Day All


    i have a Function e.g


    Code:
    public String Getdata(String mystr)
    
    {
    
    //Do what ever
    
    //return  a String
    
    }


    and i want to call this function and pass data in Javascript like this

    Code:
    function KeyPress() {
                var TExtbox1 = document.getElementById('Text1');
            
             if (TExtbox1.value.length == 2) {
    
            //call the function here and pass the textbox1 value.  
    
       return false;
             }
            }

    Thanks
    Few companies that installed computers to reduce the employment of clerks have realized their expectations.... They now need more and more expensive clerks even though they call them "Developers" or "Programmers."

  2. #2
    Join Date
    Sep 2008
    Location
    Netherlands
    Posts
    865

    Re: How to Call a Server side Function on the Client side Pin

    Take a look at this. I believe that is wat you're looking for.

  3. #3
    Join Date
    Dec 2007
    Location
    South Africa
    Posts
    263

    Re: How to Call a Server side Function on the Client side Pin

    Good Day Danny

    Thank you for your kind Replies. This is what i have done so far


    i have a HTML textbox defined like this


    Code:
    <input type="Text" id="Text1" onkeypress="keyPress()" />

    and on the Server side , i am using page method , i have a function that is defined like this

    Code:
     
       [WebMethod, System.Web.Script.Services.ScriptMethod]
        public static string Getadata(String Data)
        {
          String Scriptt  = Data;
          return Scriptt;
        }


    and i access this method like this on the client side

    Code:
       function keyPress() {
              var tb = document.getElementById('Text1');
              if (tb.value.length == 2)
                  PageMethods.Getadata(tb.value, myFunction);
              return false;
          }
          function myFunction(msg) {
              alert(msg);
          }

    and its working fine, but now i want to know how to use this in a normal asp.net textbox , because it does not have a keypress event and the defination of the textbox is like this

    Code:
    <asp:TextBox ID="Text2" runat="server"></asp:TextBox>
    Thanks
    Few companies that installed computers to reduce the employment of clerks have realized their expectations.... They now need more and more expensive clerks even though they call them "Developers" or "Programmers."

  4. #4
    Join Date
    Jul 2001
    Location
    Sunny South Africa
    Posts
    11,284

    Re: How to Call a Server side Function on the Client side Pin

    Have you tried something like this :

    Code:
    <asp:textBox id=myID onkeypress="javascript:keypress()">
    Also, vuyiswam, your signature is too long, it breaks up post - flow. Please try to shorten it. Thank you.

    Hannes

  5. #5
    Join Date
    Dec 2007
    Location
    South Africa
    Posts
    263

    Re: How to Call a Server side Function on the Client side Pin

    Good Day

    My javascript looks like this

    Code:
      
    <script type="text/javascript">
          function keyPress() {
              var txt2 = document.getElementById("<%=txt2p%>");
              alert(txt2);
              if (txt2.value.length <= 2) 
              {  
                  PageMethods.Getadata(txt2.value, myFunction);
              }
              return false;
          }
          function myFunction(msg) {
              alert(msg);
          }
      </script>
    the asp.net textbox does not a .value property in javascript

    Thanks
    Few companies that installed computers to reduce the employment of clerks have realized their expectations.... They now need more and more expensive clerks even though they call them "Developers" or "Programmers."

  6. #6
    Join Date
    Jul 2001
    Location
    Sunny South Africa
    Posts
    11,284

    Re: How to Call a Server side Function on the Client side Pin

    Is this a new question or what??

    I suggest you study up on the JavaScript DOM. Do a google search on that

    You can get the value of a textbox with JavaScript, like this :

    Code:
    document.getElementById(id).value
    Please, I'm asking nicely, and the last time, edit your signature to be shorter, please.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured