也想飞翔

笑看天边云卷云舒
posts - 3, comments - 2, trackbacks - 0, articles - 0
  博客园 :: 首页 :: 新随笔 :: 联系 :: 订阅 订阅 :: 管理

公告

2007年3月12日

1、如果要获取母板页中的某一个控件的值,可以使用 Master.FindControl() 方法。
母板页部分代码...
<asp:Label ID="labNotice" runat="server" Text="Label001" ></asp:Label>
...



内容页中的部分code...
Label myLabel=new Label();
myLabel=(Label)Master.FindControl("labNotice");
string myText=myLabel.Text;

myText 的值就是"Label001"

2、可以通过创建@MasterType 指令 创建对此母板页的强类型饮用。

下面掩饰如何设置母板页中 Calendar控件的SelectedDate 属性的值。

首先在MasterPage.cs 中添加如下代码

MasterPage.cs...

/// <summary>
    /// mpCalendarDate 的摘要说明, 强命名MasterPage ,设置 MasterPage 公共属性值
    /// </summary>
    public DateTime mpCalendarDate
    {
        get
        {
            return Calendar1.SelectedDate;
        }
        set
        {
            Calendar1.SelectedDate = value;
        }
    }
...


内容页.aspx <%@ Page Language="C#" MasterPageFile="~/MasterPage.master" AutoEventWireup="true" CodeFile="NewsListByDate.aspx.cs" Inherits="NewsListByDate" Title="Untitled Page" %>
<%@ MasterType VirtualPath="~/MasterPage.master" %>

...

注意,内容页中添加一行:<%@ MasterType VirtualPath="~/MasterPage.master" %>  这就是强引用。

内容页.cs
                 DateTime Date = DateTime.Now;

                /// <summary>
                /// mpCalendarDate 的摘要说明, 强命名MasterPage ,设置 MasterPage 公共属性值
                /// 内容页需要添加强命名MasterPage:<%@ MasterType VirtualPath="~/MasterPage.master" %>
                /// </summary>
                Master.mpCalendarDate = Date;

...

这样就可以使用代码动态来设置母板页中控件的值了。

posted @ 2007-03-12 22:19 叶翔 阅读(864) 评论(0) 编辑

2006年2月23日

posted @ 2006-02-23 09:02 叶翔 阅读(1463) 评论(0) 编辑

这是从WebHTMLEditer2.80 asp版附带的sample中提取出来的,我只不过把它改到ASP.NET环境下。

    //==============
    
// 错误提示!
    
//==============
    private void GoError(string strError)
    
{
        Response.Write(
"<script language=javascript>alert('" + strError + "\\n\\n系统将自动返回前一页面');history.back();</script>");

    }

 

posted @ 2006-02-23 08:51 叶翔 阅读(1392) 评论(2) 编辑