0

我有两aspx页,bottle.aspxcap.aspx

一旦我填写了表格,bottle.aspx我应该能够将该表格提交给cap.aspx,这工作正常。但是在bottle.aspx页面中hidden fields,我将值分配给hidden fields函数中的值JavaScript。现在,当我尝试使用获取文件中的hidden field值时,我正在获取值。cap.aspx.csRequest.Form["HiddenfiledId"]null

Bottle.aspx代码:

<%@ Page Title="" Language="C#" MasterPageFile="~/Meb.Master" AutoEventWireup="true" CodeBehind="bottle.aspx.cs" Inherits="xxxx" %>

<asp:Content ID="Content1" ContentPlaceHolderID="MHead" runat="server">
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="NavBarContent" runat="server">
</asp:Content>
<asp:Content ID="Content3" ContentPlaceHolderID="Breadcrumbs" runat="server">
</asp:Content>
<asp:Content ID="Content4" ContentPlaceHolderID="MiddleColumnContent" runat="server">
    <style>
        .vTop {
            vertical-align: top !important;
        }

        .rd1 {
            margin: 1px 0px 0 6px;
        }

        .auto-style2 {
            margin-right: 294px;
        }
    </style>
    <script type="text/javascript">
        function SelectSingleRadiobutton(rdbtnid,checked) {
            var rdBtn = document.getElementById(rdbtnid);

            var rdBtnList = document.getElementsByTagName("input");
            for (i = 0; i < rdBtnList.length; i++) {
                if (rdBtnList[i].type == "radio" && rdBtnList[i].id != rdBtn.id) {
                    rdBtnList[i].checked = false;
                }
            }
            if (checked == false) {
                document.getElementById("rbNewMessage").checked = false;
            }
            var hdnfldVariable = document.getElementById("hdnfldVariable")
            hdnfldVariable.value = rdbtnid;
        }
    </script>
    <form runat="server" method="post" action="Cap.aspx">
        <asp:gridview id="gvStatusMessages">
            <Columns>  
                <asp:TemplateField ItemStyle-CssClass="vTop rd1">
                    <ItemTemplate>
                        <asp:RadioButton ID="rbSelectStatus" OnClick="javascript:SelectSingleRadiobutton(this.id,false)" />
                        <asp:HiddenField ID="hdnfldVariable" runat="server" />
                    </ItemTemplate>
                </asp:TemplateField>
            </Columns>
        </asp:gridView>
        <asp:Button runat="server" Text="Submit Message" ID="btnSubmit" CssClass="bluelink" OnClientClick="f1(this)" />
        <asp:HiddenField ID="hdfButtonClciked" runat="server" />
    </form>
</asp:Content>

现在在cap.aspx.cs文件中,我试图获得hidden field价值。

 string btnClicked = Request.Form["hdfButtonClciked"];
 string msNum = Request.Form["hdnfldVariable"]

但它是返回null值。

任何想法?

4

1 回答 1

0

尝试

方法1

HiddenField btnClicked = ((HiddenField)Page.PreviousPage.FindControl("hdfButtonClciked")).Value;
HiddenField msNum = ((HiddenField)Page.PreviousPage.FindControl("hdnfldVariable")).Value;

或者

方法2

使用Session而不是HiddenField.

注意:第一种方法很可能会生成NullReferenceException,请小心处理。

于 2017-03-22T04:30:33.620 回答