|
-
August 5th, 2010, 03:10 AM
#1
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."
-
August 5th, 2010, 03:35 AM
#2
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.
-
August 6th, 2010, 01:29 AM
#3
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."
-
August 6th, 2010, 02:58 AM
#4
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
-
August 6th, 2010, 03:48 AM
#5
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."
-
August 6th, 2010, 04:15 AM
#6
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|