Click here to Skip to main content
15,886,518 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
.i want to create hyperlink in csharp no of times the data is fetched from database and then i want to call a javascript function from code behind and i want pass two parameters to this javascript function..
the problem is that when i pass two parameters that javascript function doesnot call.
please tell me what is the problem in this code.
XML
string qry = "SELECT  DISTINCT Sender, Receiver FROM Message WHERE Sender='" + dRow["UserName"].ToString() + "'and receiver ='" + username+"'";
            SqlDataAdapter da = new SqlDataAdapter(qry, conn);
            DataSet ds3 = new DataSet();
            da.Fill(ds3);
            conn.Close();
          
             if (ds3.Tables[0].Rows.Count > 0)
             {
                

                sb.Append("<li><a href =''" + "onclick='OpenChatBox()'>" + dRow["UserName"].ToString() + "</a></li>");

                              }
             ChatContent.InnerHtml = sb.ToString()
Posted
Comments
Brij 2-May-11 7:07am    
Your code is not looking complete
Ra-one 2-May-11 7:41am    
It doesnt seem that you have called javascript anywhere in above code.

Make sure your method (with two parameters) exists.
See here to make sure you are doing the right thing - http://www.devcurry.com/2009/01/execute-javascript-function-from-aspnet.html[^].
 
Share this answer
 
 
Share this answer
 
C#
foreach (DataRow dRow in ds.Tables[0].Rows)
         {

MIDL
string qry = "SELECT  DISTINCT Sender, Receiver FROM Message WHERE Sender='" + dRow["UserName"].ToString() + "'and receiver ='" + username+"'";


SqlDataAdapter da = new SqlDataAdapter(qry, conn);
DataSet ds3 = new DataSet();
da.Fill(ds3);
conn.Close();
if (ds3.Tables[0].Rows.Count > 0)
{
sb.Append("<li><a href =''" + "onclick='OpenChatBox(dRow["UserName"].ToString(),dRow["User1"].ToString())'>" + dRow["UserName"].ToString() + "</a></li>");

}
ChatContent.InnerHtml = sb.ToString();
}


this is the javascript function which i ma calling...
XML
<script language="javascript">

    function OpenChatBox(sender, receiver) {
        var win = window.open("ChatBox.aspx?agent=" + sender + "&user=" + receiver, "", "status=0,toolbar=0, menubar=0, width=490, height=650");
    }

   </script>


sorry here is the complete code
in this code i ma trying to create hyperlink and calling javascript function with two parameters on click of hyperlink its not working...it works fine when i pass no parameters..
 
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