ASP.Net:如何调用从内容页事件处理程序母版页事件处理程序? [英] ASP.Net : How to call a Master page event handler from Content page event handler?

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

问题描述

我有一个母版页在那里我有一个链接按钮。在内容页中的一个,我需要隐藏的LinkBut​​ton和图像按钮代替。图像按钮的Click事件处理程序应完全做同样的事情作为链接按钮,在母版页中单击事件。那么,有没有从内容页图像按钮单击事件处理程序调用主页链接按钮单击事件处理程序的方式吗?

I have a master page where in I have a link button. In one of the content pages, I need to hide the linkbutton and replace with image button. The click event handler for image button should exactly do the same thing as the click event of the link button in master page. So is there a way of calling the Master page link button click event handler from the Image button click event handler in Content page?

我已经研究并似乎有一个的情况下,很多法师页面要调用的事件处理程序中的内容页...

I have researched and there seem to be a lot in case Master page wants to call the event handler in Content page...

任何INOUT将是非常美联社preciated。

Any inout will be highly appreciated.

感谢

推荐答案

在你的母版页的code后面更换事件处理受保护的关键字来公布。

In your master page's code behind replace the protected keyword on the event handler to public.

    public void LinkButton1_Click(object sender, EventArgs e)
    {
        //Do Stuff Here
    }

在您的内容页使用硕士指令

IN your content page use the Master Type Directive

<%@ MasterType VirtualPath="~/masters/SourcePage.master"" %> 

在背后的内容页面的code调用主事件处理程序如下:

In the code behind for the content page call the Master event handler as follows

    protected void ImageButton1_Click(object sender, ImageClickEventArgs e)
    {
        this.Master.LinkButton1_Click(sender, e);
    }

请注意在code是C#。

Note the code is C#.

我期待为更直接调用母版页的事件处理程序

I'm looking into calling the master pages event handler more directly

这篇关于ASP.Net:如何调用从内容页事件处理程序母版页事件处理程序?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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