前台和后台传参问题
前台
<script language ="javascript" type ="text/javascript" >
function divcenter(i) {
var divId = document.getElementById('div1sss');
document.getElementById('div1sss').innerHTML = i;
document.getElementById('div1sss').style.display = "block";
}
</script>
<div id="div1sss" style =" display :none ; position :absolute ; background-color :Yellow ;"></div>
后台
protected void Button2_Click(object sender, EventArgs e)
{
SqlDataBase Sql1 = new SqlDataBase();
Sql1.Open();
string strlinshi = string.Format("select neirong from JM_TB where id='{0}'",dex8 );
SqlDataAdapter myapter = new SqlDataAdapter(strlinshi, SqlDataBase.Cn);
DataSet ds = new DataSet();
myapter.Fill(ds);
if (ds.Tables[0].Rows.Count == 0)
{
// Label1.Text = "无内容显示";
// Label1.Visible = true;
Page.RegisterStartupScript("", "<script>divcenter('无内容');</script>");
}
else
{
string f = ds.Tables[0].Rows[0][0].ToString();
Sql1.Close();
Page.RegisterStartupScript("", "<script> divcenter('f');</script>");
// Label1.Text = f;
// Label1.Visible = true;
}
}
我是在GRIDVIEW的rowcommand中调用的CLICK
Page.RegisterStartupScript("", "<script> divcenter('f');</script>");
divcenter()里面随便写个内容就能成功 怎么让它显示我的变量F的内容啊?
------解决方案--------------------
"<script> divcenter('"+f+"');</script>"
------解决方案--------------------Page.RegisterStartupScript("", "<script> divcenter(''+f+'');</script>");
试试看 不行就用双引号- - 我这边没环境不好测试