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?

0
ITSASPDOTNET
6/25/2008 1:27:54 AM
📁 asp.net.networking-webservices
📃 2181 articles.
⭐ 0 followers.

💬 2 Replies
👁️‍🗨️ 1988 Views

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."
0
Careed
6/25/2008 1:55:24 AM

 Yes there is a way. This is discussed here : http://www.asp.net/ajax/documentation/live/tutorials/ExposingWebServicesToAJAXTutorial.aspx

1.> Set the EnablePageMethods attribute to true

something like....

<asp:ScriptManager ID="ScriptManager1" 
    EnablePageMethods="true"
    EnablePartialRendering="true" runat="server" />
2.> Specify  your method as static and decorate it with the WebMethod attribute

[WebMethod]
public static string YourMethod(string name)
{
    return "Hello " + name;
}

3.> Call it from Javascript

<script>
    function buttonClick(){
        alert(PageMethods.YourMethod("John Doe"));
    }
script>

 


http://www.aglux.ca
0
ericpanorel
6/25/2008 9:57:46 PM