using ICallbackeventhandler to call code behind functions form javascript in c#

May 25 2009 2:43 AM
When I use the  ICallbackeventhandler I get an error that it is not implemented by my .aspx page while the downloaded files work in the same.Could any one point out the reason.
Just add name space System.web.UI.Icallbackhandler in your c# code in aspx.cs file and the page wont work.
I t is meant to call code behind  methods from javascript.
Thanks,
Roopangee

Answers (3)

0
Rodick Wu

Rodick Wu

  • 0
  • 170
  • 0
May 26 2009 1:01 AM
oh, It's badly for typesetting in this forum.
0
Rodick Wu

Rodick Wu

  • 0
  • 170
  • 0
May 26 2009 1:00 AM
.aspx file function GetWeather() { var value=document.getElementById("txtName").value; UseCallback(value,""); } function GetWeatherFromServer(value,context) { alert(value);//get your result from DB } GetWeather();
0
Rodick Wu

Rodick Wu

  • 0
  • 170
  • 0
May 26 2009 12:56 AM
Sorry for not clearly about your issue, and this is my example for ICallbackeventhandler, hope helps for you. public partial class Index : System.Web.UI.Page, ICallbackEventHandler { protected void Page_Load(object sender, EventArgs e) { string reference = Page.ClientScript.GetCallbackEventReference(this, "arg", "GetWeatherFromServer", "context"); string cbScript = "function UseCallback(arg,context)" + "{" + reference + ";" + "}"; Page.ClientScript.RegisterClientScriptBlock(this.GetType(), "UseCallback", cbScript, true); } #region ICallbackEventHandler private string value = string.Empty; public string GetCallbackResult() { return value; } public void RaiseCallbackEvent(string eventArgument) { value = GetStringFromDB(eventArgument); } #endregion