菜鸟请教关于HiddenField取值的问题,在线等! 我在前台定义了<asp:HiddenField ID="hfdQeuryCondition" runat="server" Visible="false" /> ,hfdQeuryCondition用来隐藏查询条件,现在我要点击Button来打印报表,打印Gridview中的信息(所查询的),我不想在后台实现跳转,而在前台用js实现跳转,关键是怎么获得hfdQeuryCondition的值到打印报表页面,请教了! 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 document.getElementByID("<%=hfdQeuryCondition.ClientID%>") document.getElementById('IDXXX').innerText document.getElementById('<%=hfdQeuryCondition.ClientID%>').value并且 你不用设置hfdQeuryCondition 的Visible 属性,它本身就是不可见的,你设置之后 它将不会出现在页面上 JS 是找不到它的 谢谢,缺少引用问题解决了,但是运行 var strWhere = document.getElementById('<%=hfdQeuryCondition.ClientID%>').value; alert(strWhere);显示空串,还是取不到值 我在查询之后才打印的,这时hfdQeuryCondition.value已经有值了,触发onClientclick事件后才取值的,应该可行的啊 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; } 1.var HiddenValue= document.getElementById('<%=Hiddenid.ClientID%>').value; 2.順序問題:OnClientClick 在 Button_Query_ServerClick前執行。所以此時為空 針對2出現的問題,你可以在后臺最后調用JS function(). 這是隱藏控件不是FileUpload,和updatepanel無關。 删除OnClientClick="btnPrint_onclick()查询后就把数据绑定到hidden里,同时跟踪看看GetQeuryCondition中数据是否正确 谢谢,问题已经解决了,是updatepanel 问题,没有局部刷新查询条件. 求指引,谢谢 .NET报表导出excel freetextbox 怎么使用的??? .NET PDF在线阅读 查了半天也没找到答案的问题~ 高手进来讨论一下 sql server 2005问题..小弟求教.... 问个简单的问题,连接数据库区别 请问怎样在客户端用javascript计算datagrid中某一模板列值的总和啊? 高分!求表的主键 Help!!!!如何在现有的DataView表中进行SQL条件判断?并在此基础上再生成另一个DataView? 关于csdn的常识提问。新手慎入 vs2008中如何添加站点模板“AJAX Control Toolkit Web Site”
document.getElementById('<%=hfdQeuryCondition.ClientID%>').value并且 你不用设置hfdQeuryCondition 的Visible 属性,它本身就是不可见的,
你设置之后 它将不会出现在页面上 JS 是找不到它的
var strWhere = document.getElementById('<%=hfdQeuryCondition.ClientID%>').value;
alert(strWhere);
显示空串,还是取不到值
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;
}
2.順序問題:OnClientClick 在 Button_Query_ServerClick前執行。所以此時為空