将“向导步骤”控件中的隐藏字段值传递到下一个站点

时间:2009-09-22 16:57:16

标签: asp.net forms request.form

我在向提交的下一个网站发送值时遇到了一些问题。我认为问题是隐藏字段放在WizardSteps控件中,但我不知道。

这是html代码:

<asp:WizardStep runat="server" ID="Complete" Title="Trin 4" OnActivate="OnLoad_Step4">
        <div class="OrderComfirmation">
            <div class="personInformation">   
                <div class="title">Dine oplysninger <span class="personInformationParanthes">( </span><a href="javascript:WebForm_DoPostBackWithOptions(new WebForm_PostBackOptions('ctl00$Content$Wizard1$SideBarContainer$SideBarList$ctl02$SideBarButton', '', true, '', '', false, true))">ret</a> <span class="personInformationParanthes">) </span></div>                
                <div class="personalInformationLabel"><asp:Label ID="PersonInformationLabel" runat="server" Text="Label"></asp:Label></div>
            </div>
            <div class="cartList">
                <div class="cartListTitle">Indkøbskurv</div>
                <div class="cartListContent">
                    <table>
                        <tr>
                            <td class="cartListTdTitleProduct">Produkt</td>
                            <td class="cartListTdTitleQuantaty">Antal</td>
                            <td class="cartListTdTitlePrice">Stk. Pris</td>
                            <td class="cartListTdTitlePriceTotal">Pris</td>
                            <td class="cartListTdTitleDelete">Slet</td>
                        </tr>
                        <asp:DataList ID="OrderConfirmationList" runat="server" 
                            OnItemDataBound="OrderConfirmationList_ItemDataBound">
                            <ItemTemplate>
                                    <tr>
                                        <td class="cartListTdContentProduct"><%# Eval("Produkt") %></td>
                                        <td class="cartListTdContentQuantaty">
                                            <asp:Label ID="AmountLabel" runat="server" Text="Label"></asp:Label>
                                        </td>
                                        <td class="cartListTdContentPrice">
                                            <asp:Label ID="ProductPriceLabel" runat="server" Text='<%# Eval("Pris") %>'></asp:Label>,00 DKK
                                        </td>
                                        <td class="cartListTdContentPriceTotal">
                                            <asp:Label ID="PriceLabel" runat="server" Text="Label"></asp:Label>,00 DKK
                                            <asp:Label ID="ProductIDLabel" Visible="false" runat="server" Text='<%# Eval("ProductID") %>'></asp:Label>
                                        </td>
                                        <td class="cartListTdContentDelete"><a href="test.aspx?productID=<%# Eval("ProductID") %>">Slet</a></td>
                                    </tr>
                                    <tr>
                                        <td class="cartListLine" colspan="5"></td>
                                    </tr>
                            </ItemTemplate>
                        </asp:DataList>
                        <tr>
                            <td>                                    
                                <div class="cartListTdContentTotal">
                                    <div>69,00 DKK</div>
                                    <div><asp:Label ID="OrderConfirmationTotalPriceLabel" runat="server" Text="Label"></asp:Label>,00 DKK</div>
                                    <div><asp:Label ID="OrderConfirmationMomsLabel" runat="server" Text="Label"></asp:Label> DKK</div>
                                </div>
                                <div class="cartListTdContentTotalText">
                                    <div>Fragt</div>
                                    <div>Total inkl. moms</div>
                                    <div>Heraf moms</div>
                                </div>
                            </td>
                        </tr>
                    </table>
                    <asp:HiddenField ID="amount" Value='99999' runat="server" />
                </div>
            </div>
        </div>
        </asp:WizardStep>

以下是我尝试从隐藏字段中捕获值的代码:

Label1.Text = "Tester: " + Request.Form["amount"]+"<br />";

2 个答案:

答案 0 :(得分:1)

我们过去在MultiView和Wizard控件模板中使用HiddenField服务器控件时遇到了问题。它似乎没有在回发中保持价值,但不幸的是我不知道背后的原因。

考虑是否要将值与页面数据一起存储的另一个选项是将值保存在隐藏的TextBox中。

答案 1 :(得分:0)

您的HiddenField需要位于向导之外,如下所示,您需要添加一个FinishNavigationTemplate,将数据发布到您的新页面

<asp:Wizard runat="server" ID="wzd_Amount">
    <WizardSteps>
        <asp:WizardStep ID="step_Amount" runat="server">
            This is a wizard step.
        </asp:WizardStep>
    </WizardSteps>
    <FinishNavigationTemplate>
        <asp:Button runat="server" ID="btn_Finish" PostBackUrl="~/Labs/TestPage.aspx" />
    </FinishNavigationTemplate>
</asp:Wizard>
<asp:HiddenField runat="server" ID="hdf_Amount" Value="Test" />

在另一页上,您可以像这样请求数据

lbl_Test.Text = Request["hdf_Amount"];