关于数据返回给调用页面

王朝other·作者佚名  2006-11-24
宽屏版  字体: |||超大  

我们经常需要将数据返回给调用页面,下面是基本实现方式。

假设,有两个页子selectdate.aspx,calendar.aspx.

需要在selectdate.aspx做个连接,点击后打开calendar.aspx,然后在calendar.aspx中选择日期,将选择的日期返回给

selectdate.aspx(呵呵,不知道我说明白没有)

算了,看看代码吧,自然就明白了。

对了,还需要个文件用来装JAVASCRIPT的script.js

===============================================================================================

selectdate.aspx

----------------------------------------

<%@ Page language="c#" Codebehind="detail.aspx.cs" AutoEventWireup="false" Inherits="calendar.detail" %>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" >

<HTML>

<HEAD>

<title>detail</title>

<meta name="GENERATOR" Content="Microsoft Visual Studio .NET 7.1">

<meta name="CODE_LANGUAGE" Content="C#">

<meta name="vs_defaultClientScript" content="JavaScript">

<meta name="vs_targetSchema" content="http://schemas.microsoft.com/intellisense/ie5">

<script language="javascript" src="script.js"></script>

</HEAD>

<body>

<form id="Form1" method="post" runat="server">

<asp:TextBox id="CompletionDate" style="Z-INDEX: 101; LEFT: 120px; POSITION: absolute; TOP: 72px"

runat="server"></asp:TextBox>

<A href="javascript:OpenCalendar('CompletionDate', true)"><IMG style="Z-INDEX: 102; LEFT: 296px; WIDTH: 24px; POSITION: absolute; TOP: 72px; HEIGHT: 16px"

height="16" alt="" src="img/calendar.gif" width="24"></A>

</form>

</body>

</HTML>

--------------------------------------------------------------------

selectdate.aspx.cs

----------------------------------------------------------------------

sing System;

using System.Collections;

using System.ComponentModel;

using System.Data;

using System.Drawing;

using System.Web;

using System.Web.SessionState;

using System.Web.UI;

using System.Web.UI.WebControls;

using System.Web.UI.HtmlControls;

namespace calendar

{

/// <summary>

/// detail 的摘要说明。

/// </summary>

public class detail : System.Web.UI.Page

{

protected System.Web.UI.WebControls.TextBox CompletionDate;

private void Page_Load(object sender, System.EventArgs e)

{

// 在此处放置用户代码以初始化页面

}

#region Web 窗体设计器生成的代码

override protected void OnInit(EventArgs e)

{

//

// CODEGEN: 该调用是 ASP.NET Web 窗体设计器所必需的。

//

InitializeComponent();

base.OnInit(e);

}

/// <summary>

/// 设计器支持所需的方法 - 不要使用代码编辑器修改

/// 此方法的内容。

/// </summary>

private void InitializeComponent()

{

this.Load += new System.EventHandler(this.Page_Load);

}

#endregion

}

}

===========================================================================

calendar.aspx

=========================================================================

<%@ Page language="c#" Codebehind="calendar.aspx.cs" AutoEventWireup="false" Inherits="calendar.WebForm1" %>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" >

<HTML>

<HEAD>

<title>WebForm1</title>

<meta name="GENERATOR" Content="Microsoft Visual Studio .NET 7.1">

<meta name="CODE_LANGUAGE" Content="C#">

<meta name="vs_defaultClientScript" content="JavaScript">

<meta name="vs_targetSchema" content="http://schemas.microsoft.com/intellisense/ie5">

<script language="javascript">

function CloseWindow()

{

self.close();

}

</script>

</HEAD>

<body>

<form id="Calendar" method="post" runat="server">

<asp:Calendar id="Cal" style="Z-INDEX: 101; LEFT: 96px; POSITION: absolute; TOP: 16px" runat="server"

BorderWidth="1px" BackColor="#FFFFCC" Width="220px" DayNameFormat="FirstLetter" ForeColor="#663399"

Height="200px" Font-Size="8pt" Font-Names="Verdana" BorderColor="#FFCC66" ShowGridLines="True">

<TodayDayStyle ForeColor="White" BackColor="#FFCC66"></TodayDayStyle>

<SelectorStyle BackColor="#FFCC66"></SelectorStyle>

<NextPrevStyle Font-Size="9pt" ForeColor="#FFFFCC"></NextPrevStyle>

<DayHeaderStyle Height="1px" BackColor="#FFCC66"></DayHeaderStyle>

<SelectedDayStyle Font-Bold="True" BackColor="#CCCCFF"></SelectedDayStyle>

<TitleStyle Font-Size="9pt" Font-Bold="True" ForeColor="#FFFFCC" BackColor="#990000"></TitleStyle>

<OtherMonthDayStyle ForeColor="#CC9966"></OtherMonthDayStyle>

</asp:Calendar>

<asp:Button id="OKButton" style="Z-INDEX: 102; LEFT: 96px; POSITION: absolute; TOP: 224px" runat="server"

Text="O k"></asp:Button>

<a href="javascript:CloseWindow()">

<asp:Button id="CancelButton" style="Z-INDEX: 103; LEFT: 136px; POSITION: absolute; TOP: 224px"

runat="server" Text="Cancel"></asp:Button>

</a>

<asp:Label id="lblDate" style="Z-INDEX: 104; LEFT: 216px; POSITION: absolute; TOP: 232px" runat="server"></asp:Label>

<asp:DropDownList id="MonthSelect" style="Z-INDEX: 105; LEFT: 96px; POSITION: absolute; TOP: 256px"

runat="server" AutoPostBack="True"></asp:DropDownList>

<asp:DropDownList id="YearSelect" style="Z-INDEX: 106; LEFT: 248px; POSITION: absolute; TOP: 256px"

runat="server" AutoPostBack="True"></asp:DropDownList>

<input id="datechosen" type="hidden" name="datechosen" runat="server"> //这个很重要

</form>

</body>

</HTML>

---------------------------------------------------------------------------------------------------------------------------

calendar.aspx.cs

--------------------------------------------------------------------------------------------------------------------------

using System;

using System.Collections;

using System.ComponentModel;

using System.Data;

using System.Drawing;

using System.Web;

using System.Web.SessionState;

using System.Web.UI;

using System.Web.UI.WebControls;

using System.Web.UI.HtmlControls;

using System.Configuration;

namespace calendar

{

/// <summary>

/// WebForm1 的摘要说明。

/// </summary>

public class WebForm1 : System.Web.UI.Page

{

protected System.Web.UI.WebControls.Calendar Cal;

protected System.Web.UI.WebControls.

[1] [2] 下一页

 
 
 
免责声明:本文为网络用户发布,其观点仅代表作者个人观点,与本站无关,本站仅提供信息存储服务。文中陈述内容未经本站证实,其真实性、完整性、及时性本站不作任何保证或承诺,请读者仅作参考,并请自行核实相关内容。
© 2005- 王朝网络 版权所有