Pass hiddenfield value within a WizardSteps contro

2019-09-02 04:24发布

问题:

Im having some problems with sending a value to the next site on a submit. I think the problem is that the hiddenfield is placed inside a WizardSteps control, but i dont know.

Here is the html code:

<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>

And here is the code where i try to catch the value from the hiddenfield:

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

回答1:

We've had problems in the past using HiddenField server controls within MultiView and Wizard control templates. It doesn't seem to hold the value across postbacks, but unfortunately I don't know the reasons behind that.

Another option to consider if you want to store the value with the page data is to hold the value in a hidden TextBox instead.



回答2:

Your HiddenField needs to be located outside of the Wizard like below and you need to add a FinishNavigationTemplate which posts the data to your new page

<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" />

On the other page you can just Request the data like so

lbl_Test.Text = Request["hdf_Amount"];