Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/vb.net/17.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Asp.net 页面无法加载计算的ASP WEB变量_Asp.net_Vb.net - Fatal编程技术网

Asp.net 页面无法加载计算的ASP WEB变量

Asp.net 页面无法加载计算的ASP WEB变量,asp.net,vb.net,Asp.net,Vb.net,如何修复此表单,我需要在按下“显示报价”按钮后将结果重定向到其他页面;这里的主要问题是我无法保存数据并重定向它。第二页应该是这样的: The price for the vehicle you have configured is [All the options selected/computed] The offer was issued on [Calendar date1] and remains valid until [Calendar date2] 我已经用缓存测试了一些东西…仍

如何修复此表单,我需要在按下“显示报价”按钮后将结果重定向到其他页面;这里的主要问题是我无法保存数据并重定向它。第二页应该是这样的:

The price for the vehicle you have configured is [All the options selected/computed]
The offer was issued on [Calendar date1] and remains valid until [Calendar date2]
我已经用缓存测试了一些东西…仍然没有结果


Protected Sub Page_Load(sender As Object, e As EventArgs) Handles Me.Load
GetData()
End Sub
1 reference
Private Sub GetData()
lblName.Text = Cache("Name").ToString
1blPrice.Text = Cache("Price").ToString
lblofferDate.Text = Cache("offerDate").ToString
1blofferExpiration.Text = Cache("ExpirationDate").ToString
End Sub

第1页-主表格

<%@ Page Language="vb" AutoEventWireup="false" CodeBehind="WebForm1.aspx.vb" Inherits="WebApplication1.WebForm1" %>

<!DOCTYPE html>

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
    <style type="text/css">
        .auto-style1 {
            width: 100%;
        }
        .auto-style2 {
            width: 204px;
        }
        .auto-style3 {
            text-decoration: underline;
        }
        .auto-style4 {
            width: 843px;
            border-collapse: collapse;
        }
        .auto-style5 {
            height: 24px;
        }
    </style>
</head>
<body>
    <form id="form1" runat="server">
        <div>
            <table class="auto-style1">
                <tr>
                    <td class="auto-style2">
                        <asp:Label ID="Label1" runat="server" Text="Last Name:"></asp:Label>
                    </td>
                    <td>
                        <asp:TextBox ID="txtLastName" runat="server"></asp:TextBox>
                    </td>
                </tr>
                <tr>
                    <td class="auto-style2">
                        <asp:Label ID="Label2" runat="server" Text="First Name:"></asp:Label>
                    </td>
                    <td>
                        <asp:TextBox ID="txtFirstName" runat="server"></asp:TextBox>
                    </td>
                </tr>
                <tr>
                    <td class="auto-style2">
                        <asp:Label ID="Label3" runat="server" Text="Offer date:"></asp:Label>
                    </td>
                    <td>
                        <asp:Calendar ID="calOfferDate" runat="server" BackColor="White" BorderColor="#999999" CellPadding="4" DayNameFormat="Shortest" Font-Names="Verdana" Font-Size="8pt" ForeColor="Black" Height="180px" Width="200px">
                            <DayHeaderStyle BackColor="#CCCCCC" Font-Bold="True" Font-Size="7pt" />
                            <NextPrevStyle VerticalAlign="Bottom" />
                            <OtherMonthDayStyle ForeColor="#808080" />
                            <SelectedDayStyle BackColor="#666666" Font-Bold="True" ForeColor="White" />
                            <SelectorStyle BackColor="#CCCCCC" />
                            <TitleStyle BackColor="#999999" BorderColor="Black" Font-Bold="True" />
                            <TodayDayStyle BackColor="#CCCCCC" ForeColor="Black" />
                            <WeekendDayStyle BackColor="#FFFFCC" />
                        </asp:Calendar>
                    </td>
                </tr>
                <tr>
                    <td class="auto-style2">
                        <asp:Label ID="Label4" runat="server" Text="Offer expiration date:"></asp:Label>
                    </td>
                    <td>
                        <asp:Calendar ID="calExpirationDate" runat="server" BackColor="White" BorderColor="#999999" CellPadding="4" DayNameFormat="Shortest" Font-Names="Verdana" Font-Size="8pt" ForeColor="Black" Height="180px" Width="200px">
                            <DayHeaderStyle BackColor="#CCCCCC" Font-Bold="True" Font-Size="7pt" />
                            <NextPrevStyle VerticalAlign="Bottom" />
                            <OtherMonthDayStyle ForeColor="#808080" />
                            <SelectedDayStyle BackColor="#666666" Font-Bold="True" ForeColor="White" />
                            <SelectorStyle BackColor="#CCCCCC" />
                            <TitleStyle BackColor="#999999" BorderColor="Black" Font-Bold="True" />
                            <TodayDayStyle BackColor="#CCCCCC" ForeColor="Black" />
                            <WeekendDayStyle BackColor="#FFFFCC" />
                        </asp:Calendar>
                    </td>
                </tr>
            </table>
            <hr />

        </div>
        <p class="auto-style3">
            <strong>Set up your car</strong></p>
        <table class="auto-style4">
            <tr>
                <td class="auto-style5">
                    <asp:Label ID="Label5" runat="server" Text="Equipment level"></asp:Label>
                </td>
                <td class="auto-style5">
                    <asp:DropDownList ID="DropDownList1" runat="server">
                        <asp:ListItem Value="20,000">Standard</asp:ListItem>
                        <asp:ListItem Value="22,000">Evolved</asp:ListItem>
                        <asp:ListItem Value="27,000">Advanced</asp:ListItem>
                        <asp:ListItem Value="32,000">Premium</asp:ListItem>
                    </asp:DropDownList>
                </td>
            </tr>
            <tr>
                <td>
                    <asp:Label ID="Label6" runat="server" Text="Warranty type"></asp:Label>
                </td>
                <td>
                    <asp:RadioButtonList ID="RadioButtonList1" runat="server">
                        <asp:ListItem>Standard (2 years)</asp:ListItem>
                        <asp:ListItem>Extended (5 years)</asp:ListItem>
                    </asp:RadioButtonList>

                     
                </td>
            </tr>
            <tr>
                <td>
                    <asp:Label ID="Label7" runat="server" Text="Optionals"></asp:Label>
                </td>
                <td>
                    <asp:RadioButtonList ID="rblOptionals" runat="server" AutoPostBack="True">
                            <asp:ListItem Selected="True">Yes</asp:ListItem>
                            <asp:ListItem>No</asp:ListItem>
                        </asp:RadioButtonList>
                        <asp:CheckBoxList ID="cblOptionals" runat="server" RepeatDirection="Horizontal" Width="727px">
                            <asp:ListItem Value="1,000">Alloys wheels</asp:ListItem>
                            <asp:ListItem Value="1,500">Climatronic</asp:ListItem>
                            <asp:ListItem Value="1,300">Automatic pilot</asp:ListItem>
                            <asp:ListItem Value="1,000">Road alert</asp:ListItem>
                            <asp:ListItem Value="850">Navigation</asp:ListItem>
                        </asp:CheckBoxList>
                </td>

            </tr>
            <tr>
                <td class="auto-style5">
                    <asp:Label ID="Label8" runat="server" Text="Discounts"></asp:Label>
                </td>
                <td class="auto-style5"><strong><em>
                    <asp:CheckBoxList ID="cbListDiscounts" runat="server" RepeatDirection="Horizontal" CssClass="auto-style5" Width="394px" TextAlign="Left">
                        <asp:ListItem>Whole payment</asp:ListItem>
                        <asp:ListItem>CASCO insurance</asp:ListItem>
                    </asp:CheckBoxList>
                    </em></strong></td>
            </tr>
            <tr>
                <td>&nbsp;</td>
                <td>
                    <asp:Button ID="btnDisplayOffer" runat="server" BackColor="Red" ForeColor="#CCCCCC" Height="20px" Text="Display offer" Width="101px" />
                </td>
            </tr>
        </table>
    </form>
</body>
</html>

只要把你的按钮编码出来。你点击这个按钮-它保存一些数据,然后做一个简单的响应。重定向

Protected Sub btnDisplayOffer_Click(sender As Object, e As EventArgs) Handles btnDisplayOffer.Click
    SaveMyData
    Response.Redirect("Offer.aspx")
End Sub

Sub SaveMyData

    Session("Name") = txtFirstName.Text & " " & txtLastName.Text
    Session("offerDate") = calOfferDate.SelectedDate
    Session("ExpirationDate") = calExpirationDate.SelectedDate
    .etc .etc. etc.
End Sub
现在,在目标页面中,您可以在加载时执行以下操作:

Protected Sub Page_Load(sender As Object, e As EventArgs) Handles Me.Load
    if IsPostBack = False then
        GetData()
    end if
End Sub

Private Sub GetData()
    lblName.Text = Session("Name")
    1blPrice.Text = Session("Price")
    lblofferDate.Text = Session("offerDate")
    1blofferExpiration.Text = Session("ExpirationDate")
End Sub

如前所述,请始终记住检查IsPostPack=False。这是您的第一次页面加载-因此该代码块内部会变成类似于VB6或ms access表单加载事件-第一次是加载代码的位置-如果IsPostBack=False,则不会出现这种情况,然后,该代码每次都会运行—包括您在表单上放置的按钮等—因此,每当您使用该页面上的按钮或任何事件时,这些控件都会重新设置—作为一种编码习惯—将页面加载代码放在IsPostBack=False代码存根中—不要忘记使用该代码块—养成习惯—即使您我想你不需要了

只需将按钮代码编码出来即可。你点击这个按钮-它保存一些数据,然后做一个简单的响应。重定向

Protected Sub btnDisplayOffer_Click(sender As Object, e As EventArgs) Handles btnDisplayOffer.Click
    SaveMyData
    Response.Redirect("Offer.aspx")
End Sub

Sub SaveMyData

    Session("Name") = txtFirstName.Text & " " & txtLastName.Text
    Session("offerDate") = calOfferDate.SelectedDate
    Session("ExpirationDate") = calExpirationDate.SelectedDate
    .etc .etc. etc.
End Sub
现在,在目标页面中,您可以在加载时执行以下操作:

Protected Sub Page_Load(sender As Object, e As EventArgs) Handles Me.Load
    if IsPostBack = False then
        GetData()
    end if
End Sub

Private Sub GetData()
    lblName.Text = Session("Name")
    1blPrice.Text = Session("Price")
    lblofferDate.Text = Session("offerDate")
    1blofferExpiration.Text = Session("ExpirationDate")
End Sub

如前所述,请始终记住检查IsPostPack=False。这是您的第一次页面加载-因此该代码块内部会变成类似于VB6或ms access表单加载事件-第一次是加载代码的位置-如果IsPostBack=False,则不会出现这种情况,然后,该代码每次都会运行—包括您在表单上放置的按钮等—因此,每当您使用该页面上的按钮或任何事件时,这些控件都会重新设置—作为一种编码习惯—将页面加载代码放在IsPostBack=False代码存根中—不要忘记使用该代码块—养成习惯—即使您我想你不需要了

缓存不是正确的选择:它的范围是应用程序范围,这意味着所有用户都可以看到相同的数据。将会话用于特定于用户的数据单击处理程序只重定向而不调用CreateCache。这计算了一个价格,却忘记了itCache不是正确的选择:它的范围是应用程序范围,这意味着所有用户都看到相同的数据。将会话用于特定于用户的数据单击处理程序只重定向而不调用CreateCache。然后计算出一个价格,然后忘记它