Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: C#2.0 Javascript
Any one please help me...,
while running my codei'm getting error like "Unknown runtime error". Below i've attached my code.
 
<script type="text/javascript" language="javascript">
        var xmlHttp; 
        var requestURL = 'UserNameAvailability.aspx?q='; 
 
        function show_data(strName)
        { 
	        if (strName.length > 5)
	        { 
		        var url = requestURL + strName; 
                 
		        //Create the xmlHttp object to use in the request 
		        xmlHttp = GetXmlHttpObject(stateChangeHandler); 
                 
		        //Send the xmlHttp get to the specified url 
		        xmlHttp_Get(xmlHttp, url); 
	        } 
	        else 
	        { 
		        document.getElementById('UserIDCheck').innerHTML = '';
	        } 
        }
 

        function stateChangeHandler() 
        { 
	        //readyState of 4 or 'complete' represents that data has been returned 
	        if (xmlHttp.readyState == 4 || xmlHttp.readyState == 'complete')
	        { 
		        //Populate the innerHTML of the div with the results 
		        document.getElementById('UserIDCheck').innerHTML = xmlHttp.responseText;
	        } 
        	
	        if (xmlHttp.readyState == 1)
	        { 
		        document.getElementById('UserIDCheck').innerHTML = 'Loading...,';
	        }
        }
 

        function xmlHttp_Get(xmlhttp, url) 
        { 
	        xmlhttp.open('GET', url, true); 
	        xmlhttp.send(null); 
        }
 
        function GetXmlHttpObject(handler) 
        {
            var objXmlHttp;
            
            try
            { 
                // Firefox, Opera 8.0+, Safari  
	            objXmlHttp=new XMLHttpRequest();  
	            objXmlHttp.onload = handler; 
		        objXmlHttp.onerror = handler; 
            }
            catch (e)
            {  
                // Internet Explorer  try
	            try
	            {
		            objXmlHttp=new ActiveXObject("Msxml2.XMLHTTP"); 
		            objXmlHttp.onreadystatechange = handler;    
	            }
	            catch (e)
	            {    
		            try
		            {      
			            objXmlHttp=new ActiveXObject("Microsoft.XMLHTTP"); 
			            objXmlHttp.onreadystatechange = handler;         
		            }
		            catch (e)
		            {      
			            alert("Your browser does not support xmlHTTP!");      
			            return false;      
		            }
	            }
	            return objXmlHttp;
            }
        }
    </script>
 
    protected void Page_Load(object sender, EventArgs e)
    {
        if (Request.QueryString["q"] != null)
        {
            GetNames();
        }
    }
 
    private void GetNames()
    {
        string result = null;
 
        SqlConnection con = new SqlConnection();
        con.ConnectionString = "User id=xxxx;Password=xxxxx;Server=xxxxx;Database=xxxxx";
 
        SqlCommand cmd = new SqlCommand("SELECT Count(*) Cnt from Users WHERE UserID = LOWER('" + Request.QueryString["q"] + "')", con);
 
        con.Open();
 
        SqlDataReader rdr = cmd.ExecuteReader();
 
        while (rdr.Read())
        {
            result = rdr["Cnt"].ToString();
        }
 
        if (result == "0")
        {
            result = "Available";
        }
        else
        {
            result = "Already Exist!";
        }
 
        Response.Write(result);
    }
Posted 20-Mar-13 3:44am
Edited 24-Mar-13 23:43pm
v5
Comments
Prasad Khandekar at 20-Mar-13 8:57am
   
Hello,
 
Where do you get error, on client side or server side?
mn.sathish at 20-Mar-13 12:28pm
   
Server side I'm getting the result. An error has occurred When client side return the result set from server side.
ryanb31 at 20-Mar-13 9:05am
   
What line of code is causing the error?
mn.sathish at 20-Mar-13 12:31pm
   
An error has occurred in function stateChangeHandler() when i'm getting result set from server side.
line is "document.getElementById('UserIDCheck').innerHTML = xmlHttp.responseText; "
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

try this..
* default.aspx
function test(a)
{
    var xmlhttp;
    if (window.XMLHttpRequest)
    {
      xmlhttp=new XMLHttpRequest();
    }
    else
    {
      xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
    }
    xmlhttp.onreadystatechange=function()
    {
    if (xmlhttp.readyState==4 && xmlhttp.status==200)
    {
         //alert(xmlhttp.responseText);
         document.getElementById("txtStuName").innerHTML=xmlhttp.responseText;
         document.getElementById("lblStuName").innerHTML=xmlhttp.responseText;
 
    }
}
var url = "check.aspx?UserName=" +a;
xmlhttp.open("GET",url,true);
xmlhttp.send();
}
 
* check.aspx.cs
SqlConnection conn = new SqlConnection("Data Source=.\\sql2005;Initial Catalog=StudentInfo;User Id=sa;Password=123456");
    SqlCommand cmd = null;
    protected void Page_Load(object sender, EventArgs e)
    {
        conn.Open();
        string s = Request.QueryString.Get("UserName").ToString();
        
         
        if (!string.IsNullOrEmpty(s))
        {
            string str = "select * from StuInfo where StuName = '" + s + "'";
            cmd = new SqlCommand(str, conn);
            
            string status = null;
            
            SqlDataReader dr = cmd.ExecuteReader();
            if (dr.HasRows)
            {
                status = "duplicate uaername";
               
            }
            else
            {
                status = "username available";
            }
 
            Response.Write(status);
            conn.Close();
 
         }
        else
        {
            string status = "Name should not be null";
             Response.Write(status);
        }
    }
  Permalink  
v2
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 2

Finally i got the solution myself. Below are the correct code:
protected void Page_Load(object sender, EventArgs e)
    {
        if (Request.QueryString["q"] != null)
        {
            GetNames();
        }
    }
 
    private void GetNames()
    {
        string result = null;
 
        SqlConnection con = new SqlConnection();
        con.ConnectionString = "User id=xxxx;Password=xxxxx;Server=xxxxx;Database=xxxxx";
 
        SqlCommand cmd = new SqlCommand("SELECT Count(*) Cnt from Users WHERE UserID = LOWER('" + Request.QueryString["q"] + "')", con);
 
        con.Open();
 
        SqlDataReader rdr = cmd.ExecuteReader();
 
        while (rdr.Read())
        {
            result = rdr["Cnt"].ToString();
        }
 
        if (result == "0")
        {
            result = "Available";
        }
        else
        {
            result = "Already Exist!";
        }
 
        Response.Write(result);
        Response.End();
    }
  Permalink  

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
0 OriginalGriff 240
1 Kamal Rocks 184
2 BillWoodruff 173
3 PIEBALDconsult 160
4 CPallini 155
0 OriginalGriff 5,695
1 DamithSL 4,506
2 Maciej Los 4,007
3 Kornfeld Eliyahu Peter 3,480
4 Sergey Alexandrovich Kryukov 3,180


Advertise | Privacy | Mobile
Web01 | 2.8.141216.1 | Last Updated 25 Mar 2013
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100