Home     |     .Net Programming    |     cSharp Home    |     Sql Server Home    |     Javascript / Client Side Development     |     Ajax Programming

Ruby on Rails Development     |     Perl Programming     |     C Programming Language     |     C++ Programming     |     IT Jobs

Python Programming Language     |     Laptop Suggestions?    |     TCL Scripting     |     Fortran Programming     |     Scheme Programming Language


 
 
Cervo Technologies
The Right Source to Outsource

MS Dynamics CRM 3.0

Ajax Programming

Pls solve my problem


Hi
  I have a problem
  I am creating an application using ajax ,c# in .net without using any external ajax.dll

  There are 3 pages
  1)In  .aspx page, when we click a button Find, btnFindEmployee_OnClick() function is called   2) a .js  page     3) C# page

            Employee ID  :     [input]       First Name  :    Last Name  :      Title  :    Home Phone  :      Hire Date  :    Birth Date  :       [input]

  My _javascript (.js) file is

  // var AjaxEnginePage;
  var XMLHTTP;
  //var AjaxEnginePage= "WebForm1.aspx.cs";
  function CreateXMLHttp()
  {
  if (window.XMLHttpRequest)
  {
  XMLHTTP = new XMLHttpRequest();
  }
  else if (window.ActiveXObject)
  {
  XMLHTTP = new ActiveXObject("Microsoft.XMLHTTP");
  }
  }

  function btnFindEmployee_OnClick()
  {
  var empID = document.getElementById("txtEmployeeID").value;
  var requestUrl = "?Actionfiltered=FindEmployee&EmpID=" + encodeURIComponent(empID);
  CreateXMLHttp();
  if (XMLHTTP)
  {
  XMLHTTP.onfiltered= FindEmployee;
  XMLHTTP.open("GET" , requestUrl, true);
  XMLHTTP.send(null);
  }
  } //end of fun btnFindEmployee_OnClick()

  function FindEmployee()
  {
  if (XMLHTTP.readyState == 4 )
  {
  if ( XMLHTTP.status == 200 )
  {
  SetEmployeeLabels(XMLHTTP.responseXML.documentElement);
  }
  else
  {
  alert ("in FindEmployee funcCould not receive data from the server");
  document.getElementById("lblFindEmployeeStatus").inn_erhtml="";
  }
  document.getElementById("btnFindEmployee").disabled = false;
  }
  else
  {
  //document.getElementById("btnFindemployee").disabled = true;
  document.getElementById("lblFindEmployeeStatus").inn_erhtml= "<img src= http://mail.yahoo.com/config/login?/'D:\ATUL\ComnImgs\ajax-loader.gif '> loading....";
  }
  }

  function SetEmployeeLabels(ClientNode)
  {
  var txtPhone=document.getElementById("txtPhone");
  var txtFirstName=document.getElementById("txtFirstName");
  var txtLastName=document.getElementById("txtLastName");
  var txtBirthDate=document.getElementById("txtBirthDate");
  var txtHireDate=document.getElementById("txtHireDate");
  var txtTitle=document.getElementById("txtTitle");
  var lblStatus=document.getElementById("txtFindEmployeeStatus");
  //clear all textboxes
  //txtPhone.value="";
  //txtFirstName.value="";
  //txtLastName.value="";
  //txtBirthDate.value="";
  //txtTitle.value="";
  //lblStatus.value="";
  if(ClientNode!=null)
  {
  var Phone=document.getElementsByTagName('Phone');
  var FirstName=document.getElementByTagName('FirstName');
  var LasttName=document.getElementByTagName('LastName');
  var BirthDate=document.getElementByTagName('BirthDate');
  var HireDate=document.getElementByTagName('HireDate');
  var Title=document.getElementByTagName('Title');
  //sets the values in respective labels
  txtPhone.value=GetInnerText(Phone[0]);
  txtFirstName.value=GetInnerText(FirstName[0]);
  txtLastName.value=GetInnerText(LastName[0]);
  txtBirthDate.value=GetInnerText(BirthDate[0]);
  txtHireDate.value=GetInnerText(HireDate[0]);
  txtTitle.value=GetInnerText(Title[0]);
  }
  else
  {
  lblStatus.inn_erhtml="Cannot Find Employee";
  }

  }

  function GetInnerText (node)
  {
  return (node.textContent || node.innerText || node.text) ;
  }

  My .aspx.cs (ie.  C# ) page is:

  using System;
  using System.Collections;
  using System.ComponentModel;
  using System.Data;
  using System.Drawing;
  using System.Web;
  using System.Web.SessionState;
  using System.Web.UI;
  using System.Web.UI.WebControls;
  using System.Web.UI.HtmlControls;
  using System.Data.SqlClient;
  using System.Configuration;

  namespace SQLcustomers
  {
  /// <summary>
  /// Summary description for WebForm1.
  /// </summary>
  public class WebForm1 : System.Web.UI.Page
  {
  protected System.Web.UI.WebControls.TextBox txtEmployeeID;
  protected System.Web.UI.WebControls.TextBox txtFirstName;
  protected System.Web.UI.WebControls.TextBox txtLastName;
  protected System.Web.UI.WebControls.TextBox txtTitle;
  protected System.Web.UI.WebControls.TextBox txtHomePhone;
  protected System.Web.UI.WebControls.TextBox txtHireDate;
  protected System.Web.UI.WebControls.TextBox txtBirthDate;
  protected System.Web.UI.WebControls.Label lblFindEmployeeStatus;
  protected System.Web.UI.HtmlControls.HtmlInputButton b1;
  protected System.Web.UI.WebControls.Label lblEmployeeFindStatus;

  private void Page_Load(object sender, System.EventArgs e)
  {
  if (Request["Action"]!=null && Request["Action"].Trim()!="")
  {
  if (Request["Action"]=="FindEmployee" && (Request["EmpID"]!=null && Request["EmpID"].Trim()!=""))
  {
  FindEmployee(Convert.ToInt32(Request["EmpID"]));
  }
  }
  }

  // Put user code to initialize the page here

  #region Web Form Designer generated code
  override protected void OnInit(EventArgs e)
  {
  //
  // CODEGEN: This call is required by the ASP.NET Web Form Designer.
  //
  InitializeComponent();
  base.OnInit(e);
  }

  /// <summary>
  /// Required method for Designer support - do not modify
  /// the contents of this method with the code editor.
  /// </summary>
  private void InitializeComponent()
  {
  this.Load += new System.EventHandler(this.Page_Load);
  }
  #endregion

  public void FindEmployee(int empID)
  {

  SqlConnection cnn = new SqlConnection("server=192.168.1.154;uid=sa;pwd=sa@1;database=atul_sql");

  SqlCommand cmd= new SqlCommand("SELECT EmployeeID, FirstName, LastName, Title, HomePhone, HireDate, BirthDate FROM Employees WHERE EmployeeID =empID",cnn);
  cnn.Open();
  SqlDataReader dr;
  dr=cmd.ExecuteReader();
  if (dr.HasRows)
  {
  dr.Read();
  txtEmployeeID.Text=dr.GetString(0);
  }

  }

  }

  }

  --------------------------------------------------------------------------- --------------------
  I have taken help of http://www.codeproject.com/useritems/AjaxDBReadWrite.asp
  Pls help me
  I am not getting desired result as getting in the example

  Thanks'
  atul

---------------------------------
Sponsored Link

Degrees online in as fast as 1 Yr - MBA, Bachelor's, Master's, Associate -   Click now to apply

Add to del.icio.us | Digg this | Stumble it | Powered by Megasolutions Inc