In c:\inetpub\wwwroot
Create a file with .aspx extension and that file should contain only one line which is
<%@ Page Language="C#" Inherits="FetchRoles" %>
Here FetchRoles is the codebehind file which we create later.
Now in Entity Onload wherever u want  u have to link this .aspx page like the below
——
var result = FetchCurrentUserRole();
var head= document.getElementsByTagName(‘head’)[0];
var scriptTag= document.createElement(‘script’);
scriptTag.type= ‘text/javascript’;
scriptTag.text = result;
document.getElementsByTagName(‘head’)[0].appendChild(scriptTag); 
ExecuteRoleDetails();
function FetchCurrentUserRole()
{
var requestXml = "<postxml><entity>" + crmForm.ObjectTypeName + "</entity><roles>Nursing Supervisor,Logistic Staff Member,Management Staff Member,Account
Staff Member,Customer Service Staff Member,Sales Staff Member</roles></postxml>";
var responseValue;
      var currentURL = document.location.href;
             var thirdPlace = currentURL.indexOf(‘/’, 10);
             var rootUrl=  currentURL.substring(0, thirdPlace);
             var strURL = rootUrl + "/FetchRoles.aspx";
 
 try
 {
  var result = XMLPostExecute(strURL, requestXml);
  var ObjXML = new ActiveXObject("Microsoft.XMLDOM");
  ObjXML.async = false;
                ObjXML.loadXML(result.xml);
    
  if (ObjXML != null)
  { 
                  responseValue = ObjXML.selectSingleNode("//result").text;
  }  
    
 }
 catch(ex)
 {
  alert(‘Error : -> ‘ + ex.message);
 }
return responseValue ;
}
function XMLPostExecute(strTaget,strXML)
{
  try {
   var xmlhttp;
   xmlhttp = new ActiveXObject("MSXML2.XMLHTTP");
   
   xmlhttp.open("POST", strTaget , false);
   var xmldoc = new ActiveXObject ("Microsoft.XMLDOM");
   xmldoc.loadXML(strXML);
   
   xmlhttp.send(xmldoc);
   
   if( xmlhttp.status >=200 && xmlhttp.status <= 300 )
   {
    if(xmldoc.loadXML(xmlhttp.responseXML.xml))
    {
     if(xmldoc.selectSingleNode("//error"))
     {
      alert(xmldoc.selectSingleNode("//error").text); 
      return null;
     }
     else
     {
      return xmldoc;
     }
    }
   }
   return xmlhttp.responseXML.xml;
  }
  catch(ex) 
  {
   alert(‘Error in fetching current user roles : ‘ + ex.description);
   return false;
  } 
}
————
in codebehind file write this
 protected void Page_Load(Object sender, System.EventArgs e)
        {
            config = new Configuration();
            string responseString;
            base.Response.ContentType = "text/xml";
            responseString = CheckForValidUser();
            Response.Write("<result> function ExecuteRoleDetails() {" + responseString + " }</result>");
        }
        public string CheckForValidUser()
        {
            string javascriptString = string.Empty;
            StreamReader postXmlReader = new StreamReader(Request.InputStream);
            string requestXml = string.Empty;
            requestXml = postXmlReader.ReadToEnd();
            if (requestXml == string.Empty || requestXml == "")
            {
                return string.Empty;
            }
            XmlDocument entityXmlDoc = new XmlDocument();
            entityXmlDoc.LoadXml(requestXml);
            string rolesList = entityXmlDoc.SelectSingleNode("//postxml/roles").InnerText;
            string entity = entityXmlDoc.SelectSingleNode("//postxml/entity").InnerText;
        }
===============
From the above 2 code pieces we can infer like this:
in the javascript link the aspx page and pass input to the code behind file in a xml format
IN .cs file read the xml format and based on it do the calculations and send it to javascript again.
————
How to debug?
============
just build the ajax project which has cs file.
copy the dll into c:\inetpub\wwwroot\bin
Attach to w3wp.exe(world wide web publishing)
 
Advertisements

About ambatisreedhar

Developer

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s