简体   繁体   中英

ContentPage Control (mv) --> MasterPage Access

Is it possible to acces a control thats located in a content page (withing a content place holder, a multiview control to be more exactp) from the master page?

The situation is, i have a menu with buttons thats located in the master page.

Now in my content page i have 1 content place holder. In which a multiview with several views is located.

If i press a button in the menu (MasterPage) then it should open the proper view (with its controls) displayed in the content place holder area.

I have set the ActieveViewIndex=0 but i am getting all sorts of wierd behavour. I have to do something with the ActiveViewIndex++ somewhere but nothing seems to work.

edit::

string a = Request.Querystring["one"]
string b = Request.QueryString["two"]
if ( a == "addOne") // where addone is a redirection to the content page from the master page button
{
   mvMultieView.SetActiveView(vView1);
}
else
if ( b == "addTwo")
{
    mvMultieView.SetActiveView(vView2);
}

Any suggestions? Kind Regards.

您可以使用查找控件轻松完成此操作

View myView = (View)this.Master.FindControl("PlaceHolderFullMain").FindControl("PlaceHolderMain").FindControl("Mymultiview")

The way my team and I accomplished this task (and I don't know that it's the best method, but it was effective) was to use query strings (as you had in your previous question it looks like). We established a standard QS variable called iView that would determine the name of the view in question (not necessarily the control name itself, but some keyword that the content control would respond to). Since all of our pages/controls have a page base class they inherit from, we put a method in the base class (in our case it was at the page level, but in yours a control level might work) that was responsible for getting the requested view. In the control we would have a mechanism (switch perhaps) that would set the activeView. In some cases we just used the actual ID of the control (since it was a mystery to be obfuscated) and avoided the switch altogether.

http://www.mydomain.com/mypage.com?iView=mySecondView

partial class MyControl : System.Web.UI.WebControl
{
    // blah blah control stuff

    public string getRequestedView()
    {
        return (Request.QueryString["iView"]) ? Request.QueryString["iView"] : String.Empty;
    }
}

...

protected void Page_Load(object sender, EventArgs e)
{
    View myView = myMultiView.FindControl(this.getRequestedView());
    if(myView != null)
        this.MyView.SetActiveView(myView);
}

have you done this change in the Master page or content page? because i also got the same problem.

I have link buttons in my master page which i need to activate view controls in content page. the content page is not the currently loaded page.

will this method help for my solution?

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM