日期:2014-05-18  浏览次数:20520 次

asp.net里的隐藏域 怎么给不了值 急
protected void Page_Load(object sender, EventArgs e)
  {
  if (!IsPostBack)
  {
  Response.Write("<script language='javascript'>function res(){ var formData=location.search.split('&');" +
  "document.getElementById('HiddenField1').value=decodeURI(formData[1]);" +
  "document.getElementById('HiddenField2').value=decodeURI(formData[2]);" +
  "document.getElementById('HiddenField3').value=decodeURI(formData[3]);" +
  "document.getElementById('HiddenField4').value=decodeURI(formData[4]);}</script>");
  str();
  }
  }
  private void str()
  {
  string user = this.HiddenField1.Value;
  string sj = this.HiddenField2.Value;
  string qq = this.HiddenField3.Value;
  string email = this.HiddenField4.Value;
  string sql = "insert into Registration(name,phone,qq,email,time) values('" + user + "','" + sj + "','" + qq + "','" + email + "','" + DateTime.Now + "')";
  int num = DBH.ExecuteNonQuery(sql);
  if (num == 1)
  {
  Response.Write("<script>alert('^_^报名成功'"+user+")</script>");
  }
  else
  {
  Response.Write("<script>alert('>_<报名失败')</script>");
  Response.Write("<script language=javascript>window.parent.frameLeft.location.href='Index.aspx';</script>");
  }
  }

------解决方案--------------------
如果是用的服务器控件,document.getElementById('HiddenField1'). 这个ID不一定对,你应该用:服务器控件ID.ClientID
------解决方案--------------------
服务器控件的话 需要ClientID,隐藏域解析之后变成span了,你试试 document.getElementById('<%=HiddenField1.ClientID>').innerText 进行赋值