也想飞翔

笑看天边云卷云舒
随笔 - 3, 文章 - 0, 评论 - 2, 阅读 - 5585
  博客园  :: 首页  :: 新随笔  :: 联系 :: 订阅 订阅  :: 管理
< 2025年3月 >
23 24 25 26 27 28 1
2 3 4 5 6 7 8
9 10 11 12 13 14 15
16 17 18 19 20 21 22
23 24 25 26 27 28 29
30 31 1 2 3 4 5

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 叶翔 阅读(1536) 评论(0) 推荐(0) 编辑

2006年2月23日

摘要: 无标题页 ... 阅读全文

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

摘要: 这是从WebHTMLEditer2.80 asp版附带的sample中提取出来的,我只不过把它改到ASP.NET环境下。 //============== // 错误提示! //============== private void GoError(string strError) { Response.Write(""); } 阅读全文

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

点击右上角即可分享
微信分享提示