我正在使用Bootstrap折叠面板显示注册表单,如下所示:
我想从此页面获取PinSerialNumber并在按钮点击的下一页显示它,我已完成以下操作:
Page prepage = Page.PreviousPage;
if (prepage != null)
{
lblSponsorName.Text = ((TextBox)prepage.FindControl("txtSponsorName")).Text;
}
但是下一页没有显示文字。我哪里出错?
答案 0 :(得分:1)
源页面代码。我添加了以前的页面引用...(注意:它可以在不添加上一页引用的情况下使用。)
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
<link href="http://startbootstrap.com/templates/blog-home/css/bootstrap.min.css" rel="stylesheet">
<!-- Custom CSS -->
<link href="http://startbootstrap.com/templates/blog-home/css/blog-home.css" rel="stylesheet">
<!-- HTML5 Shim and Respond.js IE8 support of HTML5 elements and media queries -->
<!-- WARNING: Respond.js doesn't work if you view the page via file:// -->
<!--[if lt IE 9]>
<script src="https://oss.maxcdn.com/libs/html5shiv/3.7.0/html5shiv.js"></script>
<script src="https://oss.maxcdn.com/libs/respond.js/1.4.2/respond.min.js"></script>
<![endif]-->
</head>
<body>
<form id="form1" runat="server">
<div>
<div class="panel-group" id="accordion">
<div class="panel panel-default">
<div class="panel-heading">
<h4 class="panel-title">
<a data-toggle="collapse" data-parent="#accordion" href="#collapseOne">
Collapsible Group Item #1
</a>
</h4>
</div>
<div id="collapseOne" class="panel-collapse collapse in">
<div class="panel-body">
<asp:TextBox ID="txtSponsorName" OnTextChanged="Post" runat="server"></asp:TextBox>
<asp:Button ID="Button2" runat="server" Text="I accept the terms and conditions.Please Register Me." PostBackUrl="TargetPage.aspx" onclick="Post" />
</div>
</div>
</div>
<div class="panel panel-default">
<div class="panel-heading">
<h4 class="panel-title">
<a data-toggle="collapse" data-parent="#accordion" href="#collapseTwo">
Collapsible Group Item #2
</a>
</h4>
</div>
<div id="collapseTwo" class="panel-collapse collapse">
<div class="panel-body">
Anim pariatur cliche reprehenderit, enim eiusmod high life accusamus terry richardson ad squid. 3 wolf moon officia aute, non cupidatat skateboard dolor brunch. Food truck quinoa nesciunt laborum eiusmod. Brunch 3 wolf moon tempor, sunt aliqua put a bird on it squid single-origin coffee nulla assumenda shoreditch et. Nihil anim keffiyeh helvetica, craft beer labore wes anderson cred nesciunt sapiente ea proident. Ad vegan excepteur butcher vice lomo. Leggings occaecat craft beer farm-to-table, raw denim aesthetic synth nesciunt you probably haven't heard of them accusamus labore sustainable VHS.
</div>
</div>
</div>
<div class="panel panel-default">
<div class="panel-heading">
<h4 class="panel-title">
<a data-toggle="collapse" data-parent="#accordion" href="#collapseThree">
Collapsible Group Item #3
</a>
</h4>
</div>
<div id="collapseThree" class="panel-collapse collapse">
<div class="panel-body">
Anim pariatur cliche reprehenderit, enim eiusmod high life accusamus terry richardson ad squid. 3 wolf moon officia aute, non cupidatat skateboard dolor brunch. Food truck quinoa nesciunt laborum eiusmod. Brunch 3 wolf moon tempor, sunt aliqua put a bird on it squid single-origin coffee nulla assumenda shoreditch et. Nihil anim keffiyeh helvetica, craft beer labore wes anderson cred nesciunt sapiente ea proident. Ad vegan excepteur butcher vice lomo. Leggings occaecat craft beer farm-to-table, raw denim aesthetic synth nesciunt you probably haven't heard of them accusamus labore sustainable VHS.
</div>
</div>
</div>
</div
</div>
</form>
<!-- jQuery Version 1.11.0 -->
<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<!-- Bootstrap Core JavaScript -->
<script type="text/javascript" src="http://startbootstrap.com/templates/blog-home/js/bootstrap.min.js"></script>
</body>
</html>
目标网页。
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="TargetPage.aspx.cs" Inherits="WebApplication1.TargetPage" %>
<%@ PreviousPageType VirtualPath="~/SourcePage.aspx" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
<div>
</div>
</form>
</body>
</html>
public partial class TargetPage : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
Page prepage = Page.PreviousPage;
if (prepage != null)
{
var result = ((TextBox)prepage.FindControl("txtSponsorName")).Text;
}
}
}
答案 1 :(得分:0)
得到了我的问题的答案,这是一个非常愚蠢的问题。 在上一页的按钮点击事件中,我提供了一个PostbackURL以及书面的Response.Redirect(“”);
现在我删除了Response.Redirect(“”);它运作良好:)
抱歉所有的麻烦,感谢您抽出时间帮助我。