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

Posted by Vuyiswamb under ASP.NET on 8/5/2010 | Views : 2347 | Status : [Member] [MVP] [Administrator] | Replies : 2
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

Thank you for posting at Dotnetfunda
[Administrator]



Responses

Posted by: Narayanjha on: 8/5/2010 [Member] Starter

Up
0
Down
Hello,

Please refer below link.

http://www.codeproject.com/KB/ajax/demoajaxapp.aspx

You can achieve this functionality by using Ajax.dll

Regards,
Narayan

Vuyiswamb, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Muhilan on: 8/5/2010 [Member] Starter

Up
0
Down
you can use Microsoft.XMLDOM object to call server side function from javascript

1. create sepereate aspx page with your functionilty but it should return XML Data
ex..
lets take example.aspx

Public sReturnXml As New StringBuilder
on_PageLoad event
//public String Getdata(String mystr)

mystr= Request.querystring["val"].ToString()

//Do what ever

//return a String

sReturnXml.Append("<result1>")
sReturnXml.Append("<Result>string</Result">)
sReturnXml.Append("</result1>")
Response.ContentType = "text/xml"
Response.Write(sReturnXml.ToString)
Response.End()
}


2. How to call example.aspx

[code]
var _xmlSend = new ActiveXObject("Microsoft.XMLDOM");
var _xmlRecv = new ActiveXObject("Microsoft.XMLDOM");
var _xmlHttp = new ActiveXObject("Msxml2.XMLHTTP");


if (TExtbox1.value.length == 2) {

_xmlSend.loadXML("<node />");
_sSubmitUrl = "../example.aspx?val=" + Textbox1.value;
_xmlHttp.Open("POST", _sSubmitUrl, false);
_xmlHttp.onreadystatechange = checkReadyState;
_xmlHttp.Send(_xmlSend);

}

function checkReadyState()
{
var iState = _xmlHttp.readyState;

if (iState == 4)//readystate = completed.
{
if (_xmlHttp.responseXML.xml != ""){
_xmlRecv.loadXML(_xmlHttp.responseXML.xml);
varaiblereturnstring = _xmlRecv.selectSingleNode("/result/Result").text;
return true;
}
else {

return false;
}
}
[/code]



Vuyiswamb, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response