<script src="http://wz.csdn.net/javascripts/vote.js" type="text/javascript"></script> style="MARGIN-TOP: 0px; FLOAT: left" border="0" marginwidth="0" framespacing="0" marginheight="0" src="http://wz.csdn.net/vote.aspx?t=.net2.0%u7684%u9875%u9762%u4F20%u503C%20-%20Jay%u968F%u60F3%20-%20CSDNBlog&u=http%3A//blog.csdn.net/zhou__zhou/archive/2006/11/21/1401650.aspx" frameborder="0" noresize="noresize" width="54" scrolling="no" height="75">
.net2.0的页面传值 <script src="http://blog.csdn.net/count.aspx?ID=1401650&Type=Rank" type="text/javascript"></script>
推荐使用,可踌页面传值或对象.关于其他页面传值方式,请参考我以前的记录
开始正题:page1.aspx前台代码
<
html xmlns
=
"
http://www.w3.org/1999/xhtml
"
>
< head runat = " server " >
< title > first Page </ title >
</ head >
< body >
< form id = " form1 " runat = " server " >
< div >
输入你的名字: < br />
< asp:TextBox ID = " TextBox1 " runat = " server " >
</ asp:TextBox >
< p >
选择一个日期 < br />
< asp:Calendar ID = " Calendar1 " runat = " server " BackColor = " White " BorderColor = " Black " BorderStyle = " Solid " CellSpacing = " 1 " Font - Names = " Verdana " Font - Size = " 9pt " ForeColor = " Black " Height = " 250px " NextPrevFormat = " ShortMonth " Width = " 330px " >
< SelectedDayStyle BackColor = " #333399 " ForeColor = " White " />
< TodayDayStyle BackColor = " #999999 " ForeColor = " White " />
< DayStyle BackColor = " #CCCCCC " />
< OtherMonthDayStyle ForeColor = " #999999 " />
< NextPrevStyle Font - Bold = " True " Font - Size = " 8pt " ForeColor = " White " />
< DayHeaderStyle Font - Bold = " True " Font - Size = " 8pt " ForeColor = " #333333 " Height = " 8pt " />
< TitleStyle BackColor = " #333399 " BorderStyle = " Solid " Font - Bold = " True " Font - Size = " 12pt "
ForeColor = " White " Height = " 12pt " />
</ asp:Calendar >
</ p >
< br />
< asp:Button ID = " Button1 " runat = " server " Text = " 提交到当前页 " OnClick = " Button1_Click " />
< asp:Button ID = " Button2 " runat = " server " Text = " 提交到page2.aspx " PostBackUrl = " Page2.aspx " />
< p >
< asp:Label ID = " Label1 " runat = " server " ></ asp:Label ></ p >
</ div >
</ form >
</ body >
</ html >
< head runat = " server " >
< title > first Page </ title >
</ head >
< body >
< form id = " form1 " runat = " server " >
< div >
输入你的名字: < br />
< asp:TextBox ID = " TextBox1 " runat = " server " >
</ asp:TextBox >
< p >
选择一个日期 < br />
< asp:Calendar ID = " Calendar1 " runat = " server " BackColor = " White " BorderColor = " Black " BorderStyle = " Solid " CellSpacing = " 1 " Font - Names = " Verdana " Font - Size = " 9pt " ForeColor = " Black " Height = " 250px " NextPrevFormat = " ShortMonth " Width = " 330px " >
< SelectedDayStyle BackColor = " #333399 " ForeColor = " White " />
< TodayDayStyle BackColor = " #999999 " ForeColor = " White " />
< DayStyle BackColor = " #CCCCCC " />
< OtherMonthDayStyle ForeColor = " #999999 " />
< NextPrevStyle Font - Bold = " True " Font - Size = " 8pt " ForeColor = " White " />
< DayHeaderStyle Font - Bold = " True " Font - Size = " 8pt " ForeColor = " #333333 " Height = " 8pt " />
< TitleStyle BackColor = " #333399 " BorderStyle = " Solid " Font - Bold = " True " Font - Size = " 12pt "
ForeColor = " White " Height = " 12pt " />
</ asp:Calendar >
</ p >
< br />
< asp:Button ID = " Button1 " runat = " server " Text = " 提交到当前页 " OnClick = " Button1_Click " />
< asp:Button ID = " Button2 " runat = " server " Text = " 提交到page2.aspx " PostBackUrl = " Page2.aspx " />
< p >
< asp:Label ID = " Label1 " runat = " server " ></ asp:Label ></ p >
</ div >
</ form >
</ body >
</ html >
Protected
Sub Button1_Click()
Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click
Label1.Text = "Hello " & TextBox1.Text & "<br />" & _
"日期选择了: " & Calendar1.SelectedDate.ToShortDateString()
End Sub
Label1.Text = "Hello " & TextBox1.Text & "<br />" & _
"日期选择了: " & Calendar1.SelectedDate.ToShortDateString()
End Sub
Protected
Sub Page_Load()
Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
'当上页属性值不为空时
If Not Page.PreviousPage Is Nothing Then
Dim p_textbox1 As TextBox = CType(PreviousPage.FindControl("textbox1"), TextBox)
Dim p_Calendar1 As Calendar = CType(PreviousPage.FindControl("calendar1"), Calendar)
Label1.Text = "Hello " & p_textbox1.Text & "<br />" & _
"日期选择了: " & p_Calendar1.SelectedDate.ToShortDateString()
End If
End Sub
'当上页属性值不为空时
If Not Page.PreviousPage Is Nothing Then
Dim p_textbox1 As TextBox = CType(PreviousPage.FindControl("textbox1"), TextBox)
Dim p_Calendar1 As Calendar = CType(PreviousPage.FindControl("calendar1"), Calendar)
Label1.Text = "Hello " & p_textbox1.Text & "<br />" & _
"日期选择了: " & p_Calendar1.SelectedDate.ToShortDateString()
End If
End Sub
说明:Page1.aspx上的Button1_Click事件处理页面上服务器控件包含的值
.第二个按钮Button2完全不同。与第一个按钮不同,这个按钮不包含OnClick事件,它使用的是PostBackUrl属性。这个属性带一个字符串值,指向页面要传送到的文件位置。在本例中是Page2.aspx。这说明,现在Page2.aspx接收回送的内容和包含在Page1.aspx控件中的所有值。
要获得从前一个页面传送过来的控件值,只需创建该控件类型的一个实例,并用PreviousPage属性中的FindControl方法填充该实例。赋予FindControl方法的String值是Id值,它用于前一个页面上的服务器控件。赋予了值之后,就可以处理该服务器控件及其值了,就好像它最初位于当前页面上一样。从例子中可以看出,可以从控件中提取Text和SelectedDate属性.
来自于MSDN或实例文档
Trackback: http://tb.blog.csdn.net/TrackBack.aspx?PostId=1401650