分享
 
 
 

关于数据返回给调用页面

王朝asp·作者佚名  2006-01-09
窄屏简体版  字體: |||超大  

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

假设,有两个页子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.Button OKButton;

protected System.Web.UI.WebControls.Button CancelButton;

protected System.Web.UI.WebControls.Label lblDate;

protected System.Web.UI.WebControls.DropDownList MonthSelect;

protected System.Web.UI.HtmlControls.HtmlInputHidden datechosen;

protected System.Web.UI.WebControls.DropDownList YearSelect;

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

{

if (!Page.IsPostBack)

{

string selected = Request.QueryString["selected"];

string id = Request.QueryString["id"];

string form = Request.QueryString["formname"];

string postBack = Request.QueryString["postBack"];

Cal.FirstDayOfWeek = (System.Web.UI.WebControls.FirstDayOfWeek)1;//(System.Web.UI.WebControls.FirstDayOfWeek)Convert.ToInt32(ConfigurationSettings.AppSettings[Global.CfgKeyFirstDayOfWeek]);

try

{

Cal.SelectedDate = Cal.VisibleDate = Convert.ToDateTime(selected);

}

catch

{

Cal.SelectedDate = Cal.VisibleDate = DateTime.Today;

}

FillCalendarChoices();

SelectCorrectValues();

OKButton.Attributes.Add("onClick", "window.opener.SetDate('" + form + "','" + id + "', document.Calendar.datechosen.value," + postBack + ");");

CancelButton.Attributes.Add("onClick", "CloseWindow()");

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

}

private void FillCalendarChoices()

{

DateTime thisdate = new DateTime(DateTime.Today.Year,1,1);

for (int x=0; x<12; x++)

{

ListItem li = new ListItem(thisdate.ToString("MMMM"), thisdate.Month.ToString());

MonthSelect.Items.Add(li);

thisdate = thisdate.AddMonths(1);

}

for (int y=1994; y <= thisdate.Year; y++)

{

YearSelect.Items.Add(y.ToString());

}

}

private void SelectCorrectValues()

{

lblDate.Text = Cal.SelectedDate.ToShortDateString();

datechosen.Value = lblDate.Text;

MonthSelect.SelectedIndex = MonthSelect.Items.IndexOf(MonthSelect.Items.FindByValue(Cal.SelectedDate.Month.ToString()));

YearSelect.SelectedIndex = YearSelect.Items.IndexOf(YearSelect.Items.FindByValue(Cal.SelectedDate.Year.ToString()));

}

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

{

Cal.VisibleDate = Cal.SelectedDate;

SelectCorrectValues();

}

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

{

Cal.SelectedDate = Cal.VisibleDate

= new DateTime(Convert.ToInt32(YearSelect.SelectedItem.Value),

Convert.ToInt32(MonthSelect.SelectedItem.Value), 1);;

SelectCorrectValues();

}

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

{

Cal.SelectedDate = Cal.VisibleDate

= new DateTime(Convert.ToInt32(YearSelect.SelectedItem.Value),

Convert.ToInt32(MonthSelect.SelectedItem.Value), 1);;

SelectCorrectValues();

}

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

override protected void OnInit(EventArgs e)

{

//

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

//

InitializeComponent();

base.OnInit(e);

}

/// <summary>

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

/// 此方法的内容。

/// </summary>

private void InitializeComponent()

{

this.Cal.SelectionChanged += new System.EventHandler(this.Cal_SelectionChanged);

//this.OKButton.Click += new System.EventHandler(this.OKButton_Click);

//this.CancelButton.Click += new System.EventHandler(this.CancelButton_Click);

this.MonthSelect.SelectedIndexChanged += new System.EventHandler(this.MonthSelect_SelectedIndexChanged);

this.YearSelect.SelectedIndexChanged += new System.EventHandler(this.YearSelect_SelectedIndexChanged);

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

this.ID = "Calendar";

}

#endregion

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

{

}

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

{

}

}

}

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

script.js

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

var popUp;

function OpenCalendar(idname, postBack)

{

popUp = window.open('Calendar.aspx?formname=' + document.forms[0].name +

'&id=' + idname + '&selected=' + document.forms[0].elements[idname].value + '&postBack=' + postBack,

'popupcal',

'width=285,height=420,left=200,top=250');

}

function SetDate(formName, id, newDate, postBack)

{

eval('var theform = document.' + formName + ';');

popUp.close();

theform.elements[id].value = newDate;

if (postBack)

__doPostBack(id,'');

}

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

 
 
 
免责声明:本文为网络用户发布,其观点仅代表作者个人观点,与本站无关,本站仅提供信息存储服务。文中陈述内容未经本站证实,其真实性、完整性、及时性本站不作任何保证或承诺,请读者仅作参考,并请自行核实相关内容。
2023年上半年GDP全球前十五强
 百态   2023-10-24
美众议院议长启动对拜登的弹劾调查
 百态   2023-09-13
上海、济南、武汉等多地出现不明坠落物
 探索   2023-09-06
印度或要将国名改为“巴拉特”
 百态   2023-09-06
男子为女友送行,买票不登机被捕
 百态   2023-08-20
手机地震预警功能怎么开?
 干货   2023-08-06
女子4年卖2套房花700多万做美容:不但没变美脸,面部还出现变形
 百态   2023-08-04
住户一楼被水淹 还冲来8头猪
 百态   2023-07-31
女子体内爬出大量瓜子状活虫
 百态   2023-07-25
地球连续35年收到神秘规律性信号,网友:不要回答!
 探索   2023-07-21
全球镓价格本周大涨27%
 探索   2023-07-09
钱都流向了那些不缺钱的人,苦都留给了能吃苦的人
 探索   2023-07-02
倩女手游刀客魅者强控制(强混乱强眩晕强睡眠)和对应控制抗性的关系
 百态   2020-08-20
美国5月9日最新疫情:美国确诊人数突破131万
 百态   2020-05-09
荷兰政府宣布将集体辞职
 干货   2020-04-30
倩女幽魂手游师徒任务情义春秋猜成语答案逍遥观:鹏程万里
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案神机营:射石饮羽
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案昆仑山:拔刀相助
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案天工阁:鬼斧神工
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案丝路古道:单枪匹马
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案镇郊荒野:与虎谋皮
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案镇郊荒野:李代桃僵
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案镇郊荒野:指鹿为马
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案金陵:小鸟依人
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案金陵:千金买邻
 干货   2019-11-12
 
推荐阅读
 
 
 
>>返回首頁<<
 
靜靜地坐在廢墟上,四周的荒凉一望無際,忽然覺得,淒涼也很美
© 2005- 王朝網路 版權所有