0

我想从子页面访问asp.net母版页上的跨度,所以我在该母版页上创建了一个公共属性->
母版页

public partial class Ui_MasterPage_UI : System.Web.UI.MasterPage
    {
        public int tax = 0;

        public string notification
        {
            set
            {
                (this.FindControl("notification") as HtmlAnchor).InnerText = value.ToString();
            }
        }
       ------------------//some code
    }

现在想从子页面访问它以将一些文本设置到该 htmlanchor 标记中,以便我编写一些脚本-->

子页面

public partial class Ui_ProductDetails : System.Web.UI.Page
{
protected void ListView_ProductDetails_itemcommand(object sender, ListViewCommandEventArgs e)
    {
        Master.notification = "some text";            ////////showing error
 ------------------//some code       
    }
------------------//some code       
}

但是得到语法错误我认为上面的代码有问题,,,,,所以请检查一下......还有其他方法吗?thnku

4

1 回答 1

0

将属性 runat="server" 和 clientidmode="static" 添加到您的 HtmlAnchor 与 id "notification" 可以使代码:

(Master.FindControl("notification") as HtmlAnchor).InnerText = "whatever" 

在每个子页面中工作...

编辑:我想说你不需要那种公共方法......

于 2012-10-29T20:06:28.613 回答