在asp.net中创建超链接,并从后面的代码中调用javascript函数并传递参数 [英] create hyperlink in asp.net and call a javascript function from code behind and pass parameters
本文介绍了在asp.net中创建超链接,并从后面的代码中调用javascript函数并传递参数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
在这段代码中,我试图创建超链接,并在单击超链接时调用带有两个参数的javascript函数,它不起作用...当我不传递任何参数时,它工作正常.
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..
foreach (DataRow dRow in ds.Tables[0].Rows)
{
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="" önclick="OpenChatBox(dRow["UserName"].ToString(),dRow["User1"].ToString())">" + dRow["UserName"].ToString() + "</a></li>");
}
ChatContent.InnerHtml = sb.ToString();
}
这是我正在调用的javascript函数...
this is the javascript function which i''m calling...
<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>
推荐答案
在单引号中传递值
Pass the values in single quotes
OpenChatBox(''"+dRow["UserName"].ToString()+"'',''"+dRow["User1"].ToString()+"'')
<pre lang="xml">sb.Append("<li><a href =''''" + "onclick=''OpenChatBox(''" + dRow["UserName"].ToString() + "'',''" + dRow["UserName"].ToString() + "'')''>" + dRow["UserName"].ToString() + "</a></li>");</pre><br />
我可能会这样做.我刚刚打印了它,它给出了这样的输出
onclick ="openchatbox(``值'',``值'')''
我认为应该是这样,但它不起作用
i ma doing it like this .i have just print this it gives output like this
onclick=''openchatbox(''value'',''value'')''
i think it should be like this but it is not working
这篇关于在asp.net中创建超链接,并从后面的代码中调用javascript函数并传递参数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文