如何获取隐藏字段的值并将其传递给另一个aspx页面? (C#) [英] How to get the value of hidden field and pass it to another aspx page? (C#)

查看:86
本文介绍了如何获取隐藏字段的值并将其传递给另一个aspx页面? (C#)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何在我的代码后面获取隐藏字段的值?



我尝试使用javascript获取它,但我想在后面的代码中执行它所以当我在另一页上传递值时我可以使用它。



注意:



1.流程如下:



•首先隐藏的字段位于单独的页面(第2页)。



•然后我将使用下面的javascript代码获取其值,并使用隐藏字段的值在另一页(Page1)上设置label的值。



2. Page2被放置在Page1内的iframe。



我有什么试过:



JAVASCRIPT CODE:

how can I get the value of hidden field in my code behind?

I have tried getting it using javascript, but I want to do it in code behind so I can use it when I pass the value on the other page.

NOTE:

1.The flow of this is:

•first the hidden fields is in separate page(Page2).

•then I will get the value of that using the javascript code below and set the value of label on the other page(Page1) with the value of hidden field.

2.The Page2 is placed on the iframe inside Page1.

What I have tried:

JAVASCRIPT CODE:

function load() {
    var lblAddress = document.getElementById("hdnAddress").value;
    var lblName = document.getElementById("hdnName").value;
    var lblEmail = document.getElementById("hdnEmail").value;
    var lblPhone = document.getElementById("hdnPhone").value;
    var lblMsg = document.getElementById("hdnMsg").value;

    window.parent.document.getElementById("lblAddress").innerText = lblAddress;
    window.parent.document.getElementById("lblName").innerText = lblName;
    window.parent.document.getElementById("lblEmail").innerText = lblEmail;
    window.parent.document.getElementById("lblPhone").innerText = lblPhone;
    window.parent.document.getElementById("lblMsg").innerText = lblMsg;
    //    alert(lblAddress);
}

推荐答案

如果它上面有runat =server,那么你可以通过它的ID在后面的代码中访问它。例如,hiddenField1.Value。
If it has runat="server" on it then you can access it in code behind by it's ID. For example, hiddenField1.Value.


Hi
无法从浏览器获取标签值到服务器,而是可以尝试使用父页面中的隐藏字段在客户代码中访问相同的内容..



参考我的上一个答案如何在C#中获取从javascript到代码隐藏的值[ ^ ]


这篇关于如何获取隐藏字段的值并将其传递给另一个aspx页面? (C#)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆