Click here to Skip to main content
15,895,256 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
XML
Hello Experts,

onkeyup function of a texbox i am checking that if username already exists or not in my database.
everything work fine when i tested it into a new application.
But when i am trying to use it into my actual application it doesn't work...

my actual page is a content page of a master page... and the code below:

<pre lang="Javascript"><script language ="javascript" type = "text/javascript">


    function OnSucceeded(result,userContext, methodName)
    {
        alert(result);
        var userarray=result;
        document.getElementById('lblerror').innerHTML=userarray;
        // Not working

    }
</script> </pre>

document.getElementById('lblerror').innerHTML=userarray;.... Line is not working i am not getting the .innerHTML property while typing...

help me to assing value of userarray into label lblerror...


Thanks...
Posted
Comments
BK 4 code 23-Dec-13 23:51pm    
Here your syntax is correct and code is also correct but you should check your html where you did some mistake and please share whole HTMl so we can give you exact solution.
Karthik_Mahalingam 23-Dec-13 23:53pm    
user array is a string variable or an array ??

you can use :-

document.getElementById('lblerror').innerText=userarray;

Or
document.getElementById('lblerror').textContent=userarray;
 
Share this answer
 
you can try something like this

document.getElementById('<%=lblID.ClientID %>').childNodes[0].nodeValue = 'Your value';
 
Share this answer
 
Comments
KManishS 24-Dec-13 6:19am    
thanks for help but actually I need to change the color of label as well
ravikhoda 24-Dec-13 7:18am    
Try something like this if you want to change the color of the lable.
if that is inside any place holder / master page use client id
document.getElementById('<%=lblID.ClientID %>').style.color = 'red';

OR

document.getElementById('lblID').style.color = 'red';
KManishS 24-Dec-13 6:20am    
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title>Untitled Page</title>

<script language ="javascript" type = "text/javascript">
function checkusername(txt)
{
//alert("Hello World!");
var valusername=txt;
if(valusername!="")
{
PageMethods.checkUserName(valusername,OnSucceeded, OnFailed);
//alert("Hello World!");
}

}
function OnSucceeded(result,userContext, methodName)
{
//alert("Succeed");
var userarray=result;
document.getElementById('lblerror').innerHTML=userarray;

}
function OnFailed(error, userContext, methodName)
{
//alert("Failed");
alert("An Error Occured During Check Your UserName. Please Try After Some Time!!!");
}

</script>

</head>
<body>
<form id="form1" runat="server">
<asp:ScriptManager ID="ScriptManager1" runat="server"
EnablePageMethods="true">

<table width = "40%" border = "0" cellpadding = "0" cellspacing = "0">
<tr>
<td style =" width:30%">
<asp:TextBox ID="txtUName" onkeyup="checkusername(this.value);" runat="server" >
</td>
<td>
<asp:Label ID="lblerror" runat="server" Font-Bold="False" ForeColor="Red" Text="" >
</td>
</tr>
</table>
</form>
</body>
</html>
___________________________________________________________



using System;
using System.Configuration;
using System.Data;
using System.Data.SqlClient;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using System.Web.Services;

public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{

}
[WebMethod]
public static string checkUserName(string struname)
{
try
{
string strSQL = "Select UserFrstName From Tbl_UserRegistration where LoginID Like('" + struname + "')";
SqlConnection cnn = new SqlConnection("Data Source = MANISHPC\\DIPTIPC; User ID = PrernaStudent; Password = PrernaStudent@123; Initial Catalog = PrernaStudent; Integrated Security = False");
if (cnn.State == ConnectionState.Closed) { cnn.Open(); }
SqlDataAdapter da = new SqlDataAdapter(strSQL, cnn);
DataSet ds = new DataSet();
da.Fill(ds, "UserName");
string uerror = "";
if (ds.Tables[0].Rows.Count > 0)
{
DataRow dtr;
int i = 0;
while (i < ds.Tables[0].Rows.Count)
{
dtr = ds.Tables[0].Rows[i];
uerror = "<img height = '12px' width = '18px' alt = 'User name available' src ='UsrNameNtAvailble.png' />   UserName Already Exist!";
break;


}
}
else
{
uerror = "<img height = '12px' width = '18px' alt = 'User name available' src ='UsrNameAvailble.png' />   UserName Available!";
}
return uerror;
}
catch (Exception ex)
{
string uerror = "Error occur during checking your username";
return uerror;
}
}
}
KManishS 24-Dec-13 6:21am    
i need like this with image, help me
Hi
Try with innerText property

HTML
var lblerror = document.getElementById('<%= lblerror.ClientID %>');
           lbl.innerText = ' value changed';
 
Share this answer
 

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



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900