如何从内容页母版页上访问的.Net元素? [英] How to access .Net element on Master page from a Content page?

查看:103
本文介绍了如何从内容页母版页上访问的.Net元素?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否有可能从内部的ContentPlaceHolder 加载主该页面的主页上访问一个元素?

Is it possible to access an element on a Master page from the page loaded within the ContentPlaceHolder for the master?

我有一个ListView,列出在母版页上的导航区域人的名字。我想后,一人已被添加到ListView控件是数据绑定到表,以更新的ListView。在的ListView 目前并没有更新,直到缓存重新加载它的值。我们发现,刚刚重新运行 ListView.DataBind()将更新列表视图中的内容。我们一直无法运行 ListView.DataBind()使用母版页的网页上。

I have a ListView that lists people's names in a navigation area on the Master page. I would like to update the ListView after a person has been added to the table that the ListView is data bound to. The ListView currently does not update it's values until the cache is reloaded. We have found that just re-running the ListView.DataBind() will update a listview's contents. We have not been able to run the ListView.DataBind() on a page that uses the Master page.

下面是什么,我想做一个样本,但是编译器错误说

Below is a sample of what I wanted to do but a compiler error says

PeopleListView并不在当前上下文中存在

"PeopleListView does not exist in the current context"

GIS.master - 何处的ListView驻留

GIS.master - Where ListView resides

...<asp:ListView ID="PeopleListView"...

GISInput_People.aspx - 使用GIS.master因为它的母版页

GISInput_People.aspx - Uses GIS.master as it's master page

GISInput_People.aspx.cs

GISInput_People.aspx.cs

AddNewPerson()
{
    // Add person to table
    ....

    // Update Person List
    PeopleListView.DataBind();
    ...
}



什么是解决的最好办法在C#.NET?问题是这样

What would be the best way to resolve an issue like this in C# .Net?

推荐答案

我相信你的使用,这可能的做到这一点。 Master.FindControl或类似的东西,但你可能不应该 - 它需要的内容页面,知道太多关于母版页的结构

I believe you could do this by using this.Master.FindControl or something similar, but you probably shouldn't - it requires the content page to know too much about the structure of the master page.

我建议另一种方法,比如在射击的事件。内容区域的发射当主可以监听并重新绑定。

I would suggest another method, such as firing an event in the content area that the master could listen for and re-bind when fired.

这篇关于如何从内容页母版页上访问的.Net元素?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆