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
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.
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
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
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
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.