showModalDialog和calendar调用使用

来源:互联网 发布:淘宝店铺导航条尺寸 编辑:程序博客网 时间:2024/05/22 06:15

    重写javascript,感触颇多,以前在互联网写javascript无非判断用户登陆和密码,之后对javascript中的dom,bom进行大致的学习,之中也参阅了不少英文网站的技术文章,wrox的那本书比较浅,但是入门方便,现在的过程就是从一个不求甚解向甚解的迈进.

    window.showModalDialog使用手册

基本介绍:
showModalDialog() (IE 4+ 支持)
showModelessDialog() (IE 5+ 支持)
window.showModalDialog()方法用来创建一个显示HTML内容的模态对话框。
window.showModelessDialog()方法用来创建一个显示HTML内容的非模态对话框。

使用方法:
vReturnValue = window.showModalDialog(sURL [, vArguments] [,sFeatures])
vReturnValue = window.showModelessDialog(sURL [, vArguments] [,sFeatures])

参数说明:
sURL--必选参数,类型:字符串。用来指定对话框要显示的文档的URL。
vArguments--可选参数,类型:变体。用来向对话框传递参数。传递的参数类型不限,包括数组等。对话框通过window.dialogArguments来取得传递进来的参数。
sFeatures--可选参数,类型:字符串。用来描述对话框的外观等信息,可以使用以下的一个或几个,用分号“;”隔开。
1.dialogHeight :对话框高度,不小于100px,IE4中dialogHeight 和 dialogWidth 默认的单位是em,而IE5中是px,为方便其见,在定义modal方式的对话框时,用px做单位。
2.dialogWidth: 对话框宽度。
3.dialogLeft: 离屏幕左的距离。
4.dialogTop: 离屏幕上的距离。
5.center: {yes | no | 1 | 0 }:窗口是否居中,默认yes,但仍可以指定高度和宽度。
6.help: {yes | no | 1 | 0 }:是否显示帮助按钮,默认yes。
7.resizable: {yes | no | 1 | 0 } [IE5+]:是否可被改变大小。默认no。
8.status: {yes | no | 1 | 0 } [IE5+]:是否显示状态栏。默认为yes[ Modeless]或no[Modal]。
9.scroll:{ yes | no | 1 | 0 | on | off }:指明对话框是否显示滚动条。默认为yes。
下面几个属性是用在HTA中的,在一般的网页中一般不使用。
10.dialogHide:{ yes | no | 1 | 0 | on | off }:在打印或者打印预览时对话框是否隐藏。默认为no。
11.edge:{ sunken | raised }:指明对话框的边框样式。默认为raised。
12.unadorned:{ yes | no | 1 | 0 | on | off }:默认为no。
 其方法使用众多,原来是通过上一页面input提供的数值传给calendar的,但是由于对window.dialogArguments
的使用上未能实现,感觉这个值到目标页面怎么获得实在想不出解决方法,所以参考了另一个方法,在目标页面

RegisterHiddenField("selectedDate",this.Calendar1.SelectedDate.ToShortDateString());

就象asp加隐藏字段一样传值既简单又安全,calendar后台是这样写的

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;

namespace AdminMillionCellAspNet
{
 /// <summary>
 /// Summary description for calendar.
 /// </summary>
 public class calendar : System.Web.UI.Page
 {
  protected System.Web.UI.WebControls.Calendar Calendar1;
  protected String [][] holidays;

  private void Page_Load(object sender, System.EventArgs e)
  {
   // Put user code to initialize the page here

   holidays=new String[13][];
   for(int n=0;n<13;n++)
     holidays[n]=new string[32];
        holidays[1][26]="澳大利亚国庆节";
        holidays[2][2]="土拨鼠日";
        holidays[3][17]  = "圣帕特里克节";
        holidays[4][1]   = "愚人节";
        holidays[5][1]   = "国际劳动节";
        holidays[7][2]  = "作者的生日";
        holidays[6][6]  = "作者母亲的生日";
        holidays[9][24]  = "秋分";
        holidays[12][26] = "节礼日";
       holidays[10][1]="国庆节";
        holidays[5][1]="劳动节";
        holidays[8][1]="建军节";
       holidays[1][1]="元旦";
        holidays[2][14]  = "情人节";
        holidays[2][2]="世界湿地日";
        holidays[2][7]="国际声援南非日";
        holidays[2][2]="世界湿地日";
                 holidays[2][10]="国际气象节";
                 holidays[2][15]="中国12亿人口日";
                 holidays[2][21]="反对殖民制度斗争日";
                 holidays[2][24]="第三世界青年日";
     holidays[2][28]="世界居住条件调查日";
     holidays[3][1]="国际海豹日";
     holidays[3][3]="全国爱耳日";
     holidays[3][5]="中国青年志愿者服务日";
     holidays[3][8]="国际劳动妇女节";
     holidays[3][12]="中国植树节";
     holidays[3][14]="国际警察日";
     holidays[3][15]="国际消费者权益日";
     holidays[3][16]="手拉手情系贫困小伙伴全国统一行动日";
     holidays[3][17]="国际航海日 & 中国国医节";
     holidays[3][18]="全国科技人才活动日";
                 holidays[3][21]="世界林业日(世界森林日)";
           holidays[3][22]="世界水日";
        holidays[3][23]="世界气象日";
        holidays[3][24]="世界防治结核病日";
        holidays[4][2]="国际儿童图书日";
        holidays[4][7]="世界卫生日";
        holidays[4][21]="全国企业家活动日";
        holidays[4][22]="世界地球日 & 世界法律日";
        holidays[4][23]="世界图书和版权日";
        holidays[4][24]="世界青年反对殖民主义日 & 亚非新闻工作者日";
        holidays[4][25]="全国预防接种宣传日";
        holidays[4][26]="世界知识产权日";
        holidays[4][27]="联谊城日";
        holidays[4][30]="全国交通安全反思日";
        holidays[5][3]="世界咆哮日";
        holidays[5][4]="中国青年节";
        holidays[5][5]="全国碘缺乏病防治日";
        holidays[5][8]="世界红十字日";
        holidays[5][12]="国际护士节";
        holidays[5][15]="国际家庭(咨询)日";
        holidays[5][17]="世界电信日";
        holidays[5][18]="国际博物馆日";
        holidays[7][1]="中国共产党诞生日";
          holidays[7][2]="国际体育记者日";
        holidays[7][7]="中国人民抗日战争纪念日";
        holidays[7][11]="世界(50亿)人口日";
        holidays[7][26]="世界语(言)创立日";
        holidays[7][28]="第一次世界大战爆发";
        holidays[7][30]="非洲妇女日";
        holidays[8][1]="中国人民解放军建军节";
        holidays[8][6]="国际电影节";
        holidays[8][8]="中国男子日";
        holidays[8][26]="全国律师咨询日";
      
      //还待添加 

   //从前一个页面收参数
   if (!IsPostBack)
   {
   DateTime dt;
   try
   {
    dt = DateTime.Parse(Request.QueryString["selectedDate"]);
    
   }
   catch
   {
    dt = DateTime.Now;
   }
   Calendar1.SelectedDate = dt;
   RegisterHiddenField("selectedDate",dt.ToShortDateString());
  
  }

  }

  #region Web Form Designer generated code
  override protected void OnInit(EventArgs e)
  {
   //
   // CODEGEN: This call is required by the ASP.NET Web Form Designer.
   //
   InitializeComponent();
   base.OnInit(e);
         Calendar1.SelectionChanged += new EventHandler(Date_Selected);
  }
  
  /// <summary>
  /// Required method for Designer support - do not modify
  /// the contents of this method with the code editor.
  /// </summary>
  private void InitializeComponent()
  {   
   this.Load += new System.EventHandler(this.Page_Load);

  }
    protected void Calendar1_DayRender(object sender,DayRenderEventArgs e)
 {
  CalendarDay d=((DayRenderEventArgs)e).Day;
  TableCell c=((DayRenderEventArgs)e).Cell;
  if(d.IsOtherMonth)
  {
   c.Controls.Clear();
  }
  else
  {
   try
   {
    string Hol=holidays[d.Date.Month][d.Date.Day];
    if(Hol!=string.Empty)
     c.Controls.Add(new LiteralControl("<br>"+Hol));
   }
   catch(Exception exc)
   {
    Response.Write(exc.ToString());
   }
  }
 }
  protected void Date_Selected(object s, EventArgs e)
  {
   RegisterHiddenField("selectedDate",this.Calendar1.SelectedDate.ToShortDateString());

  }


  #endregion
 }
}
前面是给每个tablecell写liternal控件,日期中的庆祝日还能自己加,后面在pageload中将传值进行转换成日期,这里显示只要日期,错误扑抓到传空值.

前台做提交,问题解决了,发觉很多东西的确是要求甚解,越来越感觉到javascript在解决这类细致的问题上功能的强大.

原创粉丝点击