我在前台定义了<asp:HiddenField ID="hfdQeuryCondition" runat="server"  Visible="false"  /> ,hfdQeuryCondition用来隐藏查询条件,现在我要点击Button来打印报表,打印Gridview中的信息(所查询的),我不想在后台实现跳转,而在前台用js实现跳转,关键是怎么获得hfdQeuryCondition的值到打印报表页面,请教了!

解决方案 »

  1.   

    document.getElementByID("<%=hfdQeuryCondition.ClientID%>")
      

  2.   

    document.getElementById('IDXXX').innerText
      

  3.   


    document.getElementById('<%=hfdQeuryCondition.ClientID%>').value并且 你不用设置hfdQeuryCondition 的Visible 属性,它本身就是不可见的,
    你设置之后 它将不会出现在页面上 JS 是找不到它的
      

  4.   

    谢谢,缺少引用问题解决了,但是运行
       var strWhere = document.getElementById('<%=hfdQeuryCondition.ClientID%>').value;
       alert(strWhere);
    显示空串,还是取不到值
      

  5.   

    我在查询之后才打印的,这时hfdQeuryCondition.value已经有值了,触发onClientclick事件后才取值的,应该可行的啊
      

  6.   


    function btnPrint_onclick() 
    {
       var strWhere = document.getElementById('<%=hfdQeuryCondition.ClientID%>').value;
       alert(strWhere);
       openwindow("DepartmentRPT.aspx?strWhere="+strWhere,null,600,500);
    }<asp:Button id="btnPrint" CssClass="bt_print" runat="server" Text=" 打印报表" OnClientClick="btnPrint_onclick()" /><asp:HiddenField ID="hfdQeuryCondition" runat="server" />          /// <summary>
            /// 查询按钮事件
            /// </summary>
            /// <param name="sender"></param>
            /// <param name="e"></param>
            protected void Button_Query_ServerClick(object sender, EventArgs e)
            {
                strWhere = GetQeuryCondition();
                FillGridView();
               //隐藏查询条件
                this.hfdQeuryCondition.Value = GetQeuryCondition();
               if (this.gvDepartment.Rows.Count == 0)
               {
                   ScriptManager.RegisterStartupScript(this.gvDepartment, this.gvDepartment.GetType(), "NoRecord", "alert('没有记录');", true);
               }
            }
            /// <summary>
            /// 获得查询条件
            /// </summary>
            /// <returns></returns>
            protected string GetQeuryCondition()
            {            string strWhere = "";
                if (this.txtDwbh.Value != null && this.txtDwbh.Value.Trim().Length > 0)
                    strWhere = " dwbh like '%" + this.txtDwbh.Value + "%'  and ";
                if (this.txtDwmc.Text != null && this.txtDwmc.Text.Trim().Length > 0)
                    strWhere += " dwmc like '%" + this.txtDwmc.Text + "%'  and ";
                if (this.ddlstCollege.SelectedValue != null && !this.ddlstCollege.SelectedValue.Equals(""))
                    strWhere += " jw_ssdwbh like '%" + this.ddlstCollege.SelectedValue + "%'  and ";
                if (strWhere.Trim().Length > 0)
                    strWhere = strWhere.Substring(0, strWhere.LastIndexOf("and"));
                return strWhere;
            }
      

  7.   

    1.var HiddenValue= document.getElementById('<%=Hiddenid.ClientID%>').value; 
    2.順序問題:OnClientClick 在 Button_Query_ServerClick前執行。所以此時為空
      

  8.   

    針對2出現的問題,你可以在后臺最后調用JS function().
      

  9.   

    這是隱藏控件不是FileUpload,和updatepanel無關。
      

  10.   

    删除OnClientClick="btnPrint_onclick()查询后就把数据绑定到hidden里,同时跟踪看看GetQeuryCondition中数据是否正确
      

  11.   

    谢谢,问题已经解决了,是updatepanel 问题,没有局部刷新查询条件.