从代码隐藏填充隐藏字段,然后将其作为 QueryString ASP/javascript 传递回代码隐藏
我在 page_load 方法中有这段代码:
string orgId = Session["Lineage"].ToString().Split(';')[depth];
hidOrg.Value = orgId;
This in the aspx page:
<input type="hidden" id="hidOrg" runat="server" />
问题是
function doRetrieveData(objVal) {
var org = document.getElementById("hidOrg").value;
//do stuff
window.location.href = "summary.aspx?multiple=" + org
}
,在为 var org 分配隐藏的“hidOrg”字段的值时,我收到一个对象预期错误。感谢您提前提供的任何帮助。
I have this code in page_load method:
string orgId = Session["Lineage"].ToString().Split(';')[depth];
hidOrg.Value = orgId;
This in the aspx page:
<input type="hidden" id="hidOrg" runat="server" />
and
function doRetrieveData(objVal) {
var org = document.getElementById("hidOrg").value;
//do stuff
window.location.href = "summary.aspx?multiple=" + org
}
The problem is, I'm getting an object expected error when assigning var org the value of the hidden "hidOrg" field. Thanks for any help in advance.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
ASP.NET 根据控件的 命名容器。
因此,您需要将
ClientID
传递给您的 JavaScript 函数。试试这个:内联 ASP.NET 标记
其他方法:
将隐藏字段的值传递给 javascript 函数,如下所示 出色地。您需要将隐藏字段直接放在 DropDownList/Select 后面并使用 nextSibling 来获取引用到它。
设置隐藏字段的 ClientIdMode到
静态
(如果使用.NET 4.0)ASP.NET generates server-control's ClientIDs according to the control's NamingContainer.
So you need to pass the
ClientID
to your javascript function. Try this:Inline ASP.NET tags
Other approaches:
Pass the hiddenfield's value to the javascript function as well. You need to put the hiddenfield directly behind the DropDownList/Select and use nextSibling to get a reference to it.
Set the Hidden-Field's ClientIdMode to
Static
(if using .NET 4.0)