Click to See Complete Forum and Search --> : How to Call a Server side Function on the Client side Pin
vuyiswam
August 5th, 2010, 03:10 AM
Good Day All
i have a Function e.g
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
function KeyPress() {
var TExtbox1 = document.getElementById('Text1');
if (TExtbox1.value.length == 2) {
//call the function here and pass the textbox1 value.
return false;
}
}
Thanks
dannystommen
August 5th, 2010, 03:35 AM
Take a look at this (http://msdn.microsoft.com/en-us/library/aa479042.aspx). I believe that is wat you're looking for.
vuyiswam
August 6th, 2010, 01:29 AM
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
<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
[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
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
<asp:TextBox ID="Text2" runat="server"></asp:TextBox>
Thanks
HanneSThEGreaT
August 6th, 2010, 02:58 AM
Have you tried something like this :
<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
vuyiswam
August 6th, 2010, 03:48 AM
Good Day
My javascript looks like this
<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
HanneSThEGreaT
August 6th, 2010, 04:15 AM
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 :
document.getElementById(id).value
Please, I'm asking nicely, and the last time, edit your signature to be shorter, please.
codeguru.com
Copyright Internet.com Inc., All Rights Reserved.