Sunday, March 18, 2012

Call a ServerSide Script through Javascript

How to call a ServerSide Script through Javascript

public void testData()
    {
        String cbReference = Page.ClientScript.
GetCallbackEventReference(
this, "arg", "ReceiveServerData", "context");
        if (!ClientScript.
IsClientScriptBlockRegistered("CallServer"))
        {
            String callbackScript;
            callbackScript = "function CallServer(arg, context)" +
            "{" + cbReference + ";}";
            Page.ClientScript.
RegisterClientScriptBlock(this.GetType(), "CallServer", callbackScript, true);
        }
    }
protected string returnValue;
    public void RaiseCallbackEvent(String assetid)
    {
        returnValue = assetid;
        //if (LoadHandler != null)
        //    LoadHandler(assetid);
       returnValue= GetDataByAssetIdforCertificate
s(Convert.ToInt32(assetid));
    }
    public String GetCallbackResult()
    {
        StringWriter sw = new StringWriter();
        HtmlTextWriter htw = new HtmlTextWriter(sw);
        TList<IcEquipmentDetails> tlst_eqdetails = new TList<IcEquipmentDetails>();
        tlst_eqdetails = obj_Equipmentdetails.GetAll();
//.ApplyFilter("Status=true");

        if (tlst_eqdetails != null)
        {
            ddlplantEqpmentIsolation.
Items.Clear();
            ListItem firstItem = new ListItem("------Select------", "-1");
            tlst_eqdetails.Filter = "Status = true";
            ddlplantEqpmentIsolation.
DataSource = tlst_eqdetails;
            ddlplantEqpmentIsolation.
DataTextField = "Name";
            ddlplantEqpmentIsolation.
DataValueField = "ID";
            ddlplantEqpmentIsolation.
DataBind();
            //GVLookupEmp.DataSource = tlst_eqdetails;
            //GVLookupEmp.DataBind();

            ddlplantEqpmentIsolation.
Items.Insert(0, firstItem);
        }
        else
        {
            ddlplantEqpmentIsolation.
DataSource = null;
            ddlplantEqpmentIsolation.
DataBind();
        }
        ddlplantEqpmentIsolation.
RenderControl(htw);
        //return GetDataByAssetIdforCertificate
s(Convert.ToInt32(returnValue));     
        return sw.ToString();;
    }
 


type 2:

 [WebMethod(true)]
  public static string WebMethod(string passedString)
 {
      string localString = passedString;       
        //System.Threading.Thread.
Sleep(5000);
    return localString;
 }

 function CallServerFun(assetid) {
         CallServer(assetid, '');
     }
     function CallServer(assetid, context) {
     }

     function ReceiveServerData(retValue) {
    alert(retValue);
     }
 

No comments:

Post a Comment

Comments

Protected by Copyscape Plagiarism Software