0

我想在从下拉列表中选择值时显示不同的表单页面。我有一个两个网页,首先我有下拉列表,在第二页上我有一个表单,当我从下拉列表中选择值时,我想要一个表单,因为该值会出现我该怎么做,任何人都可以帮助我.

第一种形式的aspx代码:

<form id="form1" runat="server">
   <div style="margin-left: 80px">
       <asp:Label ID="lblPortal" runat="server" Text="Select Portal"></asp:Label>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
   <asp:DropDownList ID="ddlPortal" runat="server" AutoPostBack="True" 
       onselectedindexchanged="MyPage">
       <asp:ListItem>None</asp:ListItem>
       <asp:ListItem>TRAVELONG</asp:ListItem>
       <asp:ListItem>ONETRAVEL</asp:ListItem>
       <asp:ListItem>.UK</asp:ListItem>
       <asp:ListItem>.CA-YYZ</asp:ListItem>
       <asp:ListItem>.CA-YVR</asp:ListItem>
   </asp:DropDownList>
   </div>

第二种aspx形式:

<div style="margin-left: 80px">
   <asp:Label ID="lblPortal" runat="server" Text="Select Portal"></asp:Label>

   <asp:DropDownList ID="ddlPortal" runat="server" AutoPostBack="True" 
       onselectedindexchanged="MyPage_Indexchange">
       <asp:ListItem>None</asp:ListItem>
       <asp:ListItem>TRAVELONG</asp:ListItem>
       <asp:ListItem>ONETRAVEL</asp:ListItem>
       <asp:ListItem>.UK</asp:ListItem>
       <asp:ListItem>.CA-YYZ</asp:ListItem>
       <asp:ListItem>.CA-YVR</asp:ListItem>
   </asp:DropDownList>
   <asp:ValidationSummary ID="vdm" runat="server" ForeColor="Red" />
<table class="style1">
       <tr>
           <td class="style13">
               <asp:Label ID="lblTid" runat="server" Text="TID"></asp:Label>
           </td>
           <td class="style5">
               <asp:TextBox ID="tbTid" runat="server"></asp:TextBox>
           </td>
           <td class="style4">
               <asp:RequiredFieldValidator ID="rfvTid" runat="server" 
                   ControlToValidate="tbTid" ErrorMessage="Enter Tid" Font-Bold="True" 
                   ForeColor="Red">*</asp:RequiredFieldValidator>
           </td>
           <td class="style5">
               <asp:Label ID="lblUnusedTicketAmount" runat="server" 
                   Text="Unused Ticket Amount"></asp:Label>
           </td>
           <td class="style11">
               <asp:TextBox ID="tbUnusedTicketAmount" runat="server"></asp:TextBox>
           </td>
           <td>
               <asp:RequiredFieldValidator ID="rfvUnusedTicketAmount" runat="server" 
                   ControlToValidate="tbUnusedTicketAmount" ErrorMessage="Enter Amount" 
                   Font-Bold="True" ForeColor="Red">*</asp:RequiredFieldValidator>
           </td>
           <td>
               <asp:DropDownList ID="ddlUnusedAmount" runat="server">
                   <asp:ListItem>USD</asp:ListItem>
                   <asp:ListItem>CAD</asp:ListItem>
                   <asp:ListItem>GBP</asp:ListItem>
               </asp:DropDownList>
           </td>
       </tr>
       <tr>
           <td class="style14">
               <asp:Label ID="lblPNR" runat="server" Text="PNR"></asp:Label>
           </td>
           <td class="style9">
               <asp:TextBox ID="tbPNR" runat="server"></asp:TextBox>
           </td>
           <td class="style8">
               <asp:RequiredFieldValidator ID="rfvPNR" runat="server" 
                   ControlToValidate="tbPNR" ErrorMessage="Enter PNR" Font-Bold="True" 
                   ForeColor="Red">*</asp:RequiredFieldValidator>
           </td>
           <td class="style9">
               <asp:Label ID="lblAirlinePenality" runat="server" Text="Airline Penality"></asp:Label>
           </td>
           <td class="style12">
               <asp:TextBox ID="tbAirlinePenality" runat="server"></asp:TextBox>
           </td>
           <td class="style10">
               <asp:RequiredFieldValidator ID="rfvAirlinePenality" runat="server" 
                   ControlToValidate="tbAirlinePenality" ErrorMessage="Enter Penality" 
                   Font-Bold="True" ForeColor="Red">*</asp:RequiredFieldValidator>
           </td>
           <td class="style10">
               <asp:DropDownList ID="ddlAirlinePenality" runat="server">
                   <asp:ListItem>USD</asp:ListItem>
                   <asp:ListItem>CAD</asp:ListItem>
                   <asp:ListItem>GBP</asp:ListItem>
               </asp:DropDownList>
           </td>
       </tr>
       <tr>
           <td class="style13">
               <asp:Label ID="lblTicketNumber" runat="server" Text="Ticket Number"></asp:Label>
           </td>
           <td class="style5">
               <asp:TextBox ID="tbTicketNumber" runat="server"></asp:TextBox>
           </td>
           <td class="style4">
               <asp:RequiredFieldValidator ID="rfvTicketNumber" runat="server" 
                   ControlToValidate="tbTicketNumber" ErrorMessage="Enter ESAC" Font-Bold="True" 
                   ForeColor="Red">*</asp:RequiredFieldValidator>
           </td>
           <td class="style5">
               <asp:Label ID="lblNetRefundProcess" runat="server" Text="Net Refund Process"></asp:Label>
           </td>
           <td class="style11">
               <asp:TextBox ID="tbNetRefundProcess" runat="server"></asp:TextBox>
           </td>
           <td>
               <asp:RequiredFieldValidator ID="rfvNetRefundProcess" runat="server" 
                   ControlToValidate="tbNetRefundProcess" ErrorMessage="RequiredFieldValidator" 
                   Font-Bold="True" ForeColor="Red">*</asp:RequiredFieldValidator>
           </td>
           <td>
               <asp:DropDownList ID="ddlNetRefundProcess" runat="server">
                   <asp:ListItem>USD</asp:ListItem>
                   <asp:ListItem>CAD</asp:ListItem>
                   <asp:ListItem>GBP</asp:ListItem>
               </asp:DropDownList>
           </td>
       </tr>
       <tr>
           <td class="style13">
               <asp:Label ID="lblESACCode" runat="server" Text="ESAC Code"></asp:Label>
           </td>
           <td class="style5">
               <asp:TextBox ID="tbESACCode" runat="server"></asp:TextBox>
           </td>
           <td class="style4">
               <asp:RequiredFieldValidator ID="rfvESACCode" runat="server" 
                   ControlToValidate="tbESACCode" ErrorMessage="Enter ESAC code" Font-Bold="True" 
                   ForeColor="Red">*</asp:RequiredFieldValidator>
           </td>
           <td class="style5">
               <asp:Label ID="lblRefundableCommision" runat="server" 
                   Text="Refundable Commission"></asp:Label>
           </td>
           <td class="style11">
               <asp:TextBox ID="tbRefundableCommision" runat="server"></asp:TextBox>
           </td>
           <td>
               <asp:RequiredFieldValidator ID="rfvRefundableCommission" runat="server" 
                   ControlToValidate="tbRefundableCommision" ErrorMessage="RequiredFieldValidator" 
                   Font-Bold="True" ForeColor="Red">*</asp:RequiredFieldValidator>
           </td>
           <td>
               <asp:DropDownList ID="ddlRefundableCommission" runat="server">
                   <asp:ListItem>USD</asp:ListItem>
                   <asp:ListItem>CAD</asp:ListItem>
                   <asp:ListItem>GBP</asp:ListItem>
               </asp:DropDownList>
           </td>
       </tr>
       <tr>
           <td class="style13">
               <asp:Label ID="lblWaiverCode" runat="server" Text="Waiver Code"></asp:Label>
           </td>
           <td class="style5">
               <asp:TextBox ID="tbWaiverCode" runat="server"></asp:TextBox>
           </td>
           <td class="style4">
               <asp:RequiredFieldValidator ID="rfvWaiverCode" runat="server" 
                   ControlToValidate="tbWaiverCode" ErrorMessage="Enter Waiver Code" 
                   Font-Bold="True" ForeColor="Red">*</asp:RequiredFieldValidator>
           </td>
           <td class="style5">
               <asp:Label ID="lblCouponRefunded" runat="server" Text="Coupon Refunded"></asp:Label>
           </td>
           <td class="style11">
               <asp:TextBox ID="tbCouponRefund" runat="server"></asp:TextBox>
           </td>
           <td>
               <asp:RequiredFieldValidator ID="rfvCouponRefunded" runat="server" 
                   ControlToValidate="tbCouponRefund" ErrorMessage="Enter Coupon Refund" 
                   Font-Bold="True" ForeColor="Red">*</asp:RequiredFieldValidator>
           </td>
           <td>
               &nbsp;</td>
       </tr>
       <tr>
           <td class="style13">
               <asp:Label ID="Label7" runat="server" Text="Remarks"></asp:Label>
           </td>
           <td class="style5">
               <asp:TextBox ID="tbRemarks" runat="server" TextMode="MultiLine"></asp:TextBox>
           </td>
           <td class="style4">
               <asp:RequiredFieldValidator ID="rfvRemarks" runat="server" 
                   ControlToValidate="tbRemarks" ErrorMessage="Enter Remarks" Font-Bold="True" 
                   ForeColor="Red">*</asp:RequiredFieldValidator>
           </td>
           <td class="style5">
               <asp:Label ID="lblRefundType" runat="server" Text="Refund Type"></asp:Label>
           </td>
           <td class="style11">
               <asp:DropDownList ID="ddlRefundType" runat="server">
                   <asp:ListItem>Full</asp:ListItem>
                   <asp:ListItem>Partial</asp:ListItem>
               </asp:DropDownList>
           </td>
           <td>
               <asp:RequiredFieldValidator ID="rfvRefundType" runat="server" 
                   ControlToValidate="ddlRefundType" ErrorMessage="Select Refund Type" 
                   Font-Bold="True" ForeColor="Red">*</asp:RequiredFieldValidator>
           </td>
           <td>
               &nbsp;</td>
       </tr>
       <tr>
           <td class="style13" colspan="7">
               &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
               &nbsp;<asp:Button ID="Button1" runat="server" onclick="Button1_Click" 
                   Text="Submit" />
           </td>
       </tr>
   </table> 
   </div>

第二种形式的 .cs 文件代码:

protected void Page_Load(object sender, EventArgs e)
{

}
protected void MyPage_Indexchange(object sender, EventArgs e)
{
    Response.Redirect(@"~/Default.aspx");
}
4

1 回答 1

0

这可以通过使用称为跨页发布的众所周知的技术来完成。简而言之:您将帖子返回到另一个页面,您可以在其中访问原始页面的控件。

不幸的是,DropDownList没有内置此功能(例如Button具有属性的控件PostBackUrl),但PostBackOptions可以进行救援。

Form1(假设这是~\default.aspx):

protected void Page_Load(object sender, EventArgs e)
{
    var pbo = new PostBackOptions(ddlPortal);
    pbo.ActionUrl = "default2.aspx";
    pbo.AutoPostBack = true;
    ddlPortal.Attributes["onchange"] = ClientScript.GetPostBackEventReference(pbo);
}

然后添加:

<%@ PreviousPageType VirtualPath="~/default.aspx" %>

到第二种形式(假设,这是default2.aspx),并将 next 添加到第二页的Page_Load事件处理程序:

if (PreviousPage != null && PreviousPage.IsCrossPagePostBack)
{
    var ddlPortal = (DropDownList)PreviousPage.FindControl("ddlPortal");
    var selectedValue = ddlPortal.SelectedValue;
    // do something with the value from the previous page
}

这很容易,不是吗?

于 2013-03-09T16:54:48.693 回答