Hi,
How to call server side function on client side? here i want to call change() function on textbox onchange event.<script language="javascript">
function serverfunction()
{
}
</script>
<input id="Text1" onchange="javascript:serverfunction();" type="text" />code behind:
public void change()
{
Response.Write("hello");
}
![]() |
0 |
![]() |
<script type="text/javascript"> function callserver() { $get("Button1").click(); } </script>
<asp:Button ID="Button1" runat="server" style="display:none" onclick="Button1_Click" Text="Button" />
protected void Button1_Click(object sender, EventArgs e) { Response.Write("Hello");}
Better Post your code before asking some thing, some one. So that person helping u will understand u r problem Clearly
Yahoo IM : dotnetruler
I am trying to keep Frequently Asked Questions in my blog
![]() |
0 |
![]() |
Take a look over here:
How to call Server Side function from Client Side Code using PageMethods in ASP.NET AJAX
ASP.NET Grid With Excel Capabilities | 27 GridView Tips & Tricks | Hosting your site? | SQL Server Tips
![]() |
0 |
![]() |
on the server side u have to register a script like this. For that u have to call some piece of code in page load.. see the eaxmple.
protected void Page_Load(object sender, EventArgs e)
{RegisterClientScript();
}
private void RegisterClientScript()
{
try
{
ClientScriptManager csManager = Page.ClientScript;
String csReference = csManager.GetCallbackEventReference(this, "arg", "SavePopupResult", "SavePopupWait()");
String callbackScript = "function CallServer(arg, context) { ";
callbackScript += csReference + "; }";
csManager.RegisterClientScriptBlock(this.GetType(), "CallServer", callbackScript, true);
}
catch (Exception RegisterClientScriptException)
{
throw RegisterClientScriptException;
}
}
//here CallServer is the server side function tht i will call fromclient sede
now see the client side code.. code in my aspx
function SavePopup(blockId,modifiedDate,roomTypeDetailId,roomAllocated,onePersonRate,multiplePersonRate,extraAdultRate,extraChildRate,persons,children)
{
var eventArgument = "";
eventArgument += modifiedDate + "##";
eventArgument += roomTypeDetailId + "##";
eventArgument += txtRoomAllocated.value + "##";
eventArgument += txtOnePerson.value + "##";
eventArgument += txtMultiplePerson.value + "##";
eventArgument += txtExtraAdult.value + "##";
eventArgument += txtExtraChild.value + "##";
eventArgument += ddlPersons.value + "##";
eventArgument += ddlChild.value + "##";
eventArgument += spanMinimumStay.innerHTML + "##";
eventArgument += spanSpecialDesc.innerHTML + "##";
eventArgument += spanIsSpecial.innerHTML;
HidePopup(blockId);
CallServer(eventArgument,"");}
please only refer the flow of the code as it is only an example..u have to change it the way u want...
cheers:)
Please mark as answer if it helped u!
![]() |
0 |
![]() |
Hi check this link. you will get your answer
http://www.dotnetcurry.com/ShowArticle.aspx?ID=109&AspxAutoDetectCookieSupport=1
Regards,
Avinash
Please don't forget to click "Mark as Answer" on the post that helped you.
![]() |
0 |
![]() |
Take a look at http://www.ajaxpro.info/ itβs very easy to work with. The only caveat to this is if your project is authenticated via Active Directory, then AjaxPro does not work (it runs on another process). If you need Active Directory, then I would use the call back method like above. This would be my example of the GetCallbackEventReference:
''''''''''Server Code
dim ClientXML as string = string.empty
private sub page_load.....
loadCallBack()
end sub
Private Sub loadCallBack()
Dim cbReference As String
cbReference = Page.ClientScript.GetCallbackEventReference(Me, "arg", "ReceiveServerData_Allocation", "context")
Dim callbackScript As String = ""
callbackScript &= "function CallServer(arg, context) { " & cbReference & "} ;"
Page.ClientScript.RegisterClientScriptBlock(Me.GetType(), "CallServer", callbackScript, True)
End Sub
' Returns value from server to Client
Public Function GetCallbackResult() As String Implements System.Web.UI.ICallbackEventHandler.GetCallbackResult
Return ClientXML
End Function
' Receive string from the client and process.
Public Sub RaiseCallbackEvent(ByVal eventArgument As String) Implements System.Web.UI.ICallbackEventHandler.RaiseCallbackEvent
ClientXML = "hello"
End Sub
'''''''''''''''''Client Side
function ReceiveServerData_Allocation(rValue){
//if you are passing back XML from the server you could do this
var objXMLDoc;
objXMLDoc = new ActiveXObject("Msxml2.DOMDocument");
objXMLDoc.loadXML(rValue);
//otherwise the value is in rValue.value
document.getElementById('someTextBox').value=rValue.value;
}
//sending data to the server
function sendIt(){
var obj =document.getElementById('someTextBox')
CallServer(obj.value,"");
};
HTH
Sean Gahan
![]() |
0 |
![]() |
Hi,
Please check how to use dopostback to achieve this.
http://forums.asp.net/t/1227950.aspx
Vince Xu
Microsoft Online Community Support
Please remember to mark the replies as answers if they help and unmark them if they provide no help.
![]() |
0 |
![]() |