当前位置:编程学习 > C#/ASP.NET >>

各位大虾帮帮忙!求救,在线等!

小弟我最近碰到一个问题:
我做了一个asp.net小程序,用的C#,就是在一个注册页面填写生日时,点边上的一个小按钮,就弹出一个新窗口,里面就是2个DropDownList,一个是年的选择,一个是月的选择,还有一个日期控件Calendar,我用的是window.open弹出的,我想在新窗口选一个日期后,新窗口就关闭,而注册窗口上的生日文本框就显示你选择的那个日期,怎么处理阿???看了很多资料,试了试都不行。后来用showModalDialog,可是当我选择年或月时,他会自动又弹出一个新窗口,所以就又回到window.open了,可是返回值就没发处理,请各位大虾帮帮忙!多谢了!
下面是我的弹出窗口的界面和后台代码!
Cal.aspx
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Cal.aspx.cs" Inherits="Controls_Calendar_Cal" %>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" >
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Calendar</title>
<Script language="javascript" type="text/javascript">
function CloseWindow()
{
self.close();
}
</Script>
</head>
<body bgcolor="#c0ffff" leftMargin="5" topMargin="5">
<form id="Calendar" method="post" runat="server" target="_self" submitdisabledcontrols="true">

<asp:dropdownlist id="MonthSelect" runat="server" CssClass="standard-text" Height="22px" Width="90px"
AutoPostBack="True"></asp:dropdownlist> 
<asp:dropdownlist id="YearSelect" runat="server" CssClass="standard-text" Height="22px" Width="60px"
AutoPostBack="True"></asp:dropdownlist>
<asp:calendar id="Cal" runat="server" BorderWidth="5px" BorderStyle="Double" Font-Size="XX-Small" Font-Names="Arial" BorderColor="White" DayNameFormat="Full" ForeColor="Red" FirstDayOfWeek="Monday" CssClass="standard-text" Width="403px" OnSelectionChanged="Cal_SelectionChanged" UseAccessibleHeader="False">
<todaydaystyle Font-Bold="True" ForeColor="White" BackColor="#990000"></todaydaystyle>
<daystyle BorderWidth="2px" ForeColor="#666666" BorderStyle="Solid" BorderColor="White" BackColor="#EAEAEA"></daystyle>
<dayheaderstyle ForeColor="#649CBA"></dayheaderstyle>
<selecteddaystyle Font-Bold="True" ForeColor="#333333" BackColor="#FAAD50"></selecteddaystyle>
<weekenddaystyle ForeColor="White" BackColor="#BBBBBB"></weekenddaystyle>
<othermonthdaystyle ForeColor="#666666" BackColor="White"></othermonthdaystyle>
                <TitleStyle VerticalAlign="Top" />
</asp:calendar>
            <asp:Label ID="lblDate" runat="server" Text="Label" Width="78px"></asp:Label>
        
</form>

</body>
</html>



Cal.aspx.cs

using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using OSAP.Util;

public partial class Controls_Calendar_Cal : System.Web.UI.Page
{
    private void Page_Load(object sender, EventArgs e)
    {
        if (!Page.IsPostBack)
        {
            string selected = DateTime.Now.ToString();

            try
            {
                Cal.SelectedDate = Cal.VisibleDate = Convert.ToDateTime(selected);
            }
            catch
            {
                Cal.SelectedDate = Cal.VisibleDate = DateTime.Today;
            }

            FillCalendarChoices();
            SelectCorrectValues();
        }
    }

    private void FillCalendarChoices()
    {
        DateTime thisdate = new DateTime(DateTime.Today.Year, 1, 1);

        for (int x = 0; x < 12; x++)
        {
            // Loops through 12 months of the year and fills in each month value
            ListItem li = new ListItem(thisdate.ToString("MMMM"), thisdate.Month.ToString());
            MonthSelect.Items.Add(li);
            thisdate = thisdate.AddMonths(1);
        }

        // Fills in year values and change y value to other years if necessary
        for (int y = 1990; y <= 2099; y++)
        {
            YearSelect.Items.Add(y.ToString());
        }
    }

    private void SelectCorrectValues()
    {
        lblDate.Text =Tool.DateTimeToDateString(Cal.SelectedDate);
        MonthSelect.SelectedIndex = MonthSelect.Items.IndexOf(MonthSelect.Items.FindByValue(Cal.SelectedDate.Month.ToString()));
        YearSelect.SelectedIndex = YearSelect.Items.IndexOf(YearSelect.Items.FindByValue(Cal.SelectedDate.Year.ToString()));
        
       
    }

    public void Cal_SelectionChanged(object sender,EventArgs e)
    {
        Cal.VisibleDate = Cal.SelectedDate;
        SelectCorrectValues();
        
        Response.Write("<Script language='javascript' type='text/javascript'>");
        //Response.Write("parent.document.getElementById('theTextAreaId').value=document.getElemnetById('theSelectId').value");
        Response.Write("window.opener.document.all.text1.value='from   open   windows';");
        Response.Write("window.close();");
        Response.Write("</Script>");
    }

    //**************************************************************************
    //
    // MonthSelect_SelectedIndexChanged event handler selects the first day of the month when
    // a month selection has being changed.
    //
    //**************************************************************************

    private void MonthSelect_SelectedIndexChanged(object sender,EventArgs e)
    {
        Cal.SelectedDate = Cal.VisibleDate
            = new DateTime(Convert.ToInt32(YearSelect.SelectedItem.Value),
            Convert.ToInt32(MonthSelect.SelectedItem.Value), 1); ;
        SelectCorrectValues();
    }

    //**************************************************************************
    //
    // YearSelect_SelectedIndexChanged event handler selects a year value on the Calendar control
    // when a year selection has being changed.
    //
    //**************************************************************************

    private void YearSelect_SelectedIndexChanged(object sender,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)
    {

        InitializeComponent();
        base.OnInit(e);
    }


    private void InitializeComponent()
    {
        this.MonthSelect.SelectedIndexChanged += new System.EventHandler(this.MonthSelect_SelectedIndexChanged);
        this.YearSelect.SelectedIndexChanged += new System.EventHandler(this.YearSelect_SelectedIndexChanged);
        this.Cal.SelectionChanged += new System.EventHandler(this.Cal_SelectionChanged);
        this.Load += new System.EventHandler(this.Page_Load);

    }

    #endregion

}

--------------------编程问答-------------------- 帮顶 --------------------编程问答-------------------- target=_self --------------------编程问答-------------------- target=_self我在用showModalDialog()打开窗体时,作为参数,我放进去了,但还是不好用! --------------------编程问答-------------------- mark --------------------编程问答-------------------- window.opener.document.getelementbyid("textbox1").value=日期 --------------------编程问答--------------------
window.opener.document.getElementById('theTextAreaId').value=document.getElemnetById('theSelectId').value --------------------编程问答-------------------- 不要用新窗口,用div,一会给你做个demo --------------------编程问答-------------------- 使用showModalDialog弹出的窗口,要在head里加target=_self,就不会再弹出窗口了。

========================================
 传音石——网罗天下资源 http://www.massany.com
======================================== --------------------编程问答-------------------- location.href
补充:.NET技术 ,  ASP.NET
CopyRight © 2022 站长资源库 编程知识问答 zzzyk.com All Rights Reserved
部分文章来自网络,