About the author

Vijay Kodali
E-mail me Send mail

Recent comments

Authors

Disclaimer

The opinions expressed herein are my own personal opinions and do not represent my employer's view in anyway.

© Copyright 2024

to call server side function from Javascript function?

Some times we need to call server side function from Javascript function.For example,callig a PoupWindow(with value from code behind) on HyperLink click. 

This must be implemented by creating a additional request to the web server and that’s the only way to invoke methods on the server. Page methods are used for this.

What is PageMethod?

A PageMethod is a public static method that is exposed in the code-behind of a page and can be called from the client script. PageMethods are annotated with [System.Web.Services.WebMethod] attribute.

The code is simple..

Server side function

[code:c#]

[System.Web.Services.WebMethod] public static void Score(string ID, string name, string Role) {
         try {
                //Some data manipulations 
                  return finalScore ; 
              }
         catch (Exception ex) { 
               //Response.Write(ex.ToString());
                                  } 
            } 

[/code]

//Client Side function 

[code:c#]

function score()
              {               
                  PageMethods.Score(txtID.value,txtName.value,txtRole.value);            
               } 

[/code]

<asp:HyperLink ID="btn_Test" runat="server" Text="Calculate" OnClientClick="javascript:return score();"/> 

Tags:
Categories: AJAX | ASP.NET | C#
Posted by vijay on Friday, August 24, 2007 12:23 PM
Permalink | Comments (0) | Post RSSRSS comment feed

ListSearchExtender AJAX control

The ListSearchExtender lets you search for items in a ListBox or DropDownList by typing.  The extender performs an incremental search within the ListBox based on what has been typed so far.

the code is simple 

 <ajaxToolkit:ToolkitScriptManager ID="ScriptManager1" EnablePartialRendering="true" EnableScriptGlobalization="true" EnableScriptLocalization="true" runat="Server" />

ScriptManger is required for all AJAX controls..

 <ajaxToolkit:ListSearchExtender ID="ListSearchExtender1" runat="server" TargetControlID="ListBox1" PromptCssClass="ListSearchExtenderPrompt" PromptPosition="Top"></ajaxToolkit:ListSearchExtender/>

  • PromptText - Message to display when the ListBox is given focus. 
  • TargetControlID - Control to be searched
  • PromptPosition - Indicates whether the message should appear at the Top or Bottom of the ListBox.  The default is Top.

Categories: AJAX | ASP.NET
Posted by vijay on Saturday, August 18, 2007 6:09 PM
Permalink | Comments (2) | Post RSSRSS comment feed