怎样Response.Write输出script 显示变量值?小问题

kialison 2009-02-06 11:05:11
string yazhu,Zongshu, SqlStrings;

SqlConnection con = new SqlConnection("server=127.0.0.1;database=Toupiao;uid=sa;pwd=sa");
con.Open();
SqlDataAdapter sd = new SqlDataAdapter("select * from Usermain where Username='" + username + "' ", con);
DataSet ds = new DataSet();
sd.Fill(ds);
Zongshu = ds.Tables[0].Rows[0]["Gold"].ToString();
yazhu = TextBox1.Text.ToString();

if (int.Parse(Zongshu) < int.Parse(yazhu))
{
Response.Write("<script>alert('Gold不够')</script>");
}
else
{
int Zuihou = int.Parse(Zongshu) - int.Parse(yazhu);
SqlStrings = "update Usermain set Gold = '" + Zuihou + "' where Username = '" + username + "'";
SqlCommand cmd = new SqlCommand(SqlStrings, con);
cmd.ExecuteNonQuery();
Response.Write("<script>alert('我要在这调用"yazhu"这个变量的值应该怎样写?')</script>");
}
...全文
283 2 打赏 收藏 转发到动态 举报
写回复
用AI写文章
2 条回复
切换为时间正序
请发表友善的回复…
发表回复
koukoujiayi 2009-02-06
  • 打赏
  • 举报
回复
最不影响页面的外观的写法应该是:
Page.ClientScript.RegisterStartupScript(Page.GetType(), "", "<script language=javascript>alert('"+yazhu.toString()+"') </script>");
wangguosong 2009-02-06
  • 打赏
  • 举报
回复
Response.Write(" <script>alert('"+yazhu.toString()+"') </script>");

110,533

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Web++
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧