How to call server side function on client side

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
pathipati
4/14/2009 4:35:57 AM
asp.net.networking-webservices 2181 articles. 0 followers. Follow

6 Replies
1816 Views

Similar Articles

[PageSpeed] 53
Get it on Google Play
Get it on Apple App Store

 <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
dotnetruler
4/14/2009 5:34:16 AM

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
kavita_khandhadia
4/14/2009 5:39:11 AM

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
avinash_vns
4/14/2009 6:20:00 AM
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
sean
4/14/2009 11:50:06 PM

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
Vince
4/16/2009 7:20:04 AM
Reply:

Similar Artilces:

How to call server side(C#) function from Client side(Javascript) function?
Hi i have used below functions,  function HandleOnClose() {// this function will be called after clicking browsers close button in Internet explorer if (event.clientY < 0) { event.returnValue = 'Are you sure you want to leave the page?'; } // if he clicks ok then i need to call one server side function in this instance.. else not. } <body onbeforeunload="HandleOnClose()" leftmargin="0" rightmargin="0">other controls in page..</div>  How to achieve this? Thanks MS AJAX Extensions would be the option of choice here. Combined with webservices you can...

Calling a client side function from the server side
Is it possible to call a client side function from the server side. I dont want to invoke that function through button click. I just want to call that to do some operations.  Regards, Aish Use the below code ASP.NET 2.0 Page.ClientScript.RegisterStartUpScript(this.GetType(),"callfunction","<script language=javascript>Test();</script>"); ASP.NET 1.X Page.RegisterStartUpScript("callfunction","<script language=javascript>Test();</script>"); Where Test() is the javascript function. HCHaissam Abdul MalakMCAD.NET| Blog | No, it is not possible.  The cl...

Is it possible to call client side function from server side code without initial client request?
Atlas is great. I'm using timer to periodically check database changes on server to populate client side controls with new data. Is it possible to do it without a lot of client requests to server which takes a huge useless network traffic? Server should call client side function on all connected clients when, for example, 'database updated' event occurs on server. Thanks. Hi~ Just for your interest, I think you could have a look at Comet, many web IM like Gmail's embeded Gtalk and meebo.com are built on this architecture你好! Just FYI o_O...

Calling server side function from client side alert
Hi, I am developing an ASP.Net application in which I am giving client side alert to the user with OK and Cancel buttons. Can I call a server side function from the click of this button? For e.g. I have to give user alert "Do you want to save record" with Yes/No button. On Yes button click it should go to the server and save the record. Can I call some server side function from the Yes button click? Any help in this regard will be highly appreciated. Thanks in advance. Ashish I would create a button control, say Button1. set Button1.visible=False then, ...

Calling a server-side procedure from a client-side function
I have a server side function that executes a database stored procedure, and I need to be able to call it from a javascript function.  Is this possible (without using an iFrame)?  Post back the page or use Ajax. Eric Pascarello.com | Twitter epascarello | LinkedIn...

Call client side function from server side code
My problem is that in some point of the VB.Net code I need to call a function defined in vbScript, for example: Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click   'There's some code here....   ' ...   If (SomeCondition) Then   'HERE'S WHERE I NEED TO CALL THE JAVASCRIPT FUNCTION... SO HOW CAN I DO THAT?   Else     '...   End If   ' ... End Sub The asp.net code runs to generate the html and when it is done the html is rendered in your browser. So you can't access cli...

How to Call server side and client side function on same LinkButton
hello,         i have one linkbutton when i click on linkbutton i insert record in DB using onclick=Linkbutton_click. if successfully insert then returnvalue is 1. after return 1 i want to call javascript function. how i can do this? Reply ASAP. Is It Possible? e.g. <asp:LinkButton ID="Operation_Link" runat="server" OnClick="Operation_Link_Click"></asp:LinkButton>protected void Operation_Link_Click(object sender, EventArgs e) {if (Operation_Link.Text == "SUBMIT") {ReturnValue = company.InsertCompany...

Call server side function from client side javascript
I have a javascript where I either need to call an onclick even of a server link button or I need to be able to call a server side function.   The only thing is I cant use AJAX.  Is there any way I can do this or am I spinning my wheels. Thanks!-------------Please: Don't forget to click "Mark as Answer" on the post that helped you. That way future readers will know which post solved your issue. I have a similar problem.  In my case, I would like to set a server-side session object from JavaScript.  Any suggestions?  Thanks.  Dan Sure, y...

calling server side function from client side script
i have a web form that includes a function named "koko()" in its server side class i want to write a script code in in its HTML script that will be run at the client side, and this client side script will call the function "koko()" from the server side. in brief : i want to call a server side function from a client side script... can you help me in this You can't call server-side code directly from client-side code. You can, however, trigger a postback that your server-side code watches for and triggers the server-side code appropriately. You can do some ...

Advantage of calling Webservice from server side/client side.
Hi Folks,      I've an issue sending/receiving huge amount of data from webservices. When a webmethod is called from javascript, it fails due to the size restriction of the data (> 4MB) that can be transferred. My application architechture do have webservices and asp.net applications hosted on the same server. I'm wondering, if I can make a PageMethod call to a static method on my codebehind file and then the static method makes a call to the webservice would solve the issue? Any thoughts on this, would be really helpful? (I was trying to use WSE3.0 to incres...

Client side script calling Server side functions
Hi, I'm currently developing an ajax.net enabled aspx page that contains a usercontrol (which is based on the listbox but extends it to include icons to represent invalid data). http://www.djcharlie.co.uk/WeeeCareResolutionCentre.jpg I want the onClick event of the selected TR to call an asp.net server function which then populates the controls to the right hand side in the page. Obviously because the row is just rendered HTML overriden from the base class I can only assign a javascript function to the onClick event. So I need a way of calling a server side function that will populate th...

how to call server side function from client side javascript?
Hi all, I have a image button in the update panel. I would like to call a method from server side (not from webservice) to get the variable when Onclick on the image button is invoked. Is there any way that I can able to access this function from the client script? In using the UpdatePanel, in essence, you're already doing this because there will not be a full postback.  You can make an asynchronous call to your Click method of your ImageButton.  So, what do you want to do with this "variable"?Christopher Reed"The oxen are slow, but the earth is patient."...

How to call server side function from client side JavaScript?
I want to call a server-side function, like a button's click event or just another private or public function , from a client-side JavaScript function. How do I do that? thanX AnzIf this post was useful to you, please mark it as answer.ClientSideAsp.Net | Blog Maybe alittle more that you need, but....... 1) Put a button on the page. Lets say its id is Button1. Make sure that its has causesValidation=false 2) Write the code for the button. 3) Write the following in the PAge_Load event Button1.Attributes.Add("onClick", "myJSFunction(); return false") 4) Copy this javascript...

Calling a client side control event from a server side function
I would like to know how to raise an event on a client side only control from a server side function.   For example, I have Button1 whose onclick is handled at the server. The logic behind the function will do 1 of 2 things, change the text of a label to indicate a problem or navigate to a new page.  I cannot use redirect because i need the new page to appear inside 2 of 3 existing frames.  I can manage this using an anchor on the client.  All I need to do is automatically click the anchor after I post back from the Button1.click event.I tried the following line of c...

Web resources about - How to call server side function on client side - asp.net.networking-webservices

Wave function - Wikipedia, the free encyclopedia
... (a ball attached to a spring ) in classical mechanics (A-B) and quantum mechanics (C-H). In quantum mechanics (C-H), the ball has a wave function ...

TV binging, exercise skipping linked to poor cognitive function
... their fit, less TV-addicted counterparts. In particular, couch potatoes had slightly lower brain processing speeds and worse executive function, ...

iPhone best tricks and functions - Business Insider
Your iPhone can do a lot more than you think.

Learning F# – Passing Parameters to Functions
One of the first issues I faced when learning F# was finding out how to specify multiple parameters to a function. While this might sound obvious ...

HPE Offers Catalog of Virtual Network Functions for Telcos
The vendor's OpenNFV Solution Portal gives carriers a single place to find a range of VNFs that are pre-tested to run on their networks.

7 Useful Technical SEO Functions For Your E-commerce Website
This article was co-authored by Mate Dyekiss, SEO Strategist at IMI. An e-commerce website can create all the technical SEO issues onecan imagine: ...

Using AWS Lambda functions to create print ready files
... going to tell you about our processing architecture as well as at a recent performance improvement with the integration of AWS Lambda functions. ...

Madras HC asks police to allow Tipu’s birth anniversary function
... Station on a petition filed by Ismail, General Secretary of Thamizhaga Makkal Jananayaga Katchi, seeking grant of permission to hold the function. ...

Colorado governor: This Planned Parenthood shooting may be a function of inflammatory rhetoric from bloggers ...
Via Grabien , skip to 4:45 of the clip below for the key bit. I naively thought we were (mostly) done with “climate of hate” stupidity after ...

Surprise: Binge-Watching TV May Cause a Decline in Brain Function
With the second season of Transparent only a few days away, some bad news awaits us: According to a recent study and common sense, probably, ...

Resources last updated: 1/2/2016 5:03:19 AM